home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / dev / gcc / gcc270_src.lha / gcc-2.7.0-amiga / objc-parse.y < prev    next >
GNU Bison Grammar  |  1995-06-15  |  78KB  |  2,811 lines

  1. /* YACC parser for C syntax and for Objective C.  -*-c-*-
  2.    Copyright (C) 1987, 88, 89, 92, 93, 94, 1995 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 59 Temple Place - Suite 330,
  19. Boston, MA 02111-1307, USA.  */
  20.  
  21. /* This file defines the grammar of C and that of Objective C.
  22.    ifobjc ... end ifobjc  conditionals contain code for Objective C only.
  23.    ifc ... end ifc  conditionals contain code for C only.
  24.    Sed commands in Makefile.in are used to convert this file into
  25.    c-parse.y and into objc-parse.y.  */
  26.  
  27. /* To whomever it may concern: I have heard that such a thing was once
  28.    written by AT&T, but I have never seen it.  */
  29.  
  30. %expect 48
  31.  
  32. %{
  33. #include <stdio.h>
  34. #include <errno.h>
  35. #include <setjmp.h>
  36.  
  37. #include "config.h"
  38. #include "tree.h"
  39. #include "input.h"
  40. #include "c-lex.h"
  41. #include "c-tree.h"
  42. #include "flags.h"
  43.  
  44. #ifdef MULTIBYTE_CHARS
  45. #include <stdlib.h>
  46. #include <locale.h>
  47. #endif
  48.  
  49. #include "objc-act.h"
  50.  
  51. /* Since parsers are distinct for each language, put the language string
  52.    definition here.  */
  53. char *language_string = "GNU Obj-C";
  54.  
  55. #ifndef errno
  56. extern int errno;
  57. #endif
  58.  
  59. void yyerror ();
  60.  
  61. /* Like YYERROR but do call yyerror.  */
  62. #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
  63.  
  64. /* Cause the `yydebug' variable to be defined.  */
  65. #define YYDEBUG 1
  66. %}
  67.  
  68. %start program
  69.  
  70. %union {long itype; tree ttype; enum tree_code code;
  71.     char *filename; int lineno; }
  72.  
  73. /* All identifiers that are not reserved words
  74.    and are not declared typedefs in the current block */
  75. %token IDENTIFIER
  76.  
  77. /* All identifiers that are declared typedefs in the current block.
  78.    In some contexts, they are treated just like IDENTIFIER,
  79.    but they can also serve as typespecs in declarations.  */
  80. %token TYPENAME
  81.  
  82. /* Reserved words that specify storage class.
  83.    yylval contains an IDENTIFIER_NODE which indicates which one.  */
  84. %token SCSPEC
  85.  
  86. /* Reserved words that specify type.
  87.    yylval contains an IDENTIFIER_NODE which indicates which one.  */
  88. %token TYPESPEC
  89.  
  90. /* Reserved words that qualify type: "const" or "volatile".
  91.    yylval contains an IDENTIFIER_NODE which indicates which one.  */
  92. %token TYPE_QUAL
  93.  
  94. /* Character or numeric constants.
  95.    yylval is the node for the constant.  */
  96. %token CONSTANT
  97.  
  98. /* String constants in raw form.
  99.    yylval is a STRING_CST node.  */
  100. %token STRING
  101.  
  102. /* "...", used for functions with variable arglists.  */
  103. %token ELLIPSIS
  104.  
  105. /* the reserved words */
  106. /* SCO include files test "ASM", so use something else. */
  107. %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
  108. %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
  109. %token ATTRIBUTE EXTENSION LABEL
  110. %token REALPART IMAGPART
  111.  
  112. /* Add precedence rules to solve dangling else s/r conflict */
  113. %nonassoc IF
  114. %nonassoc ELSE
  115.  
  116. /* Define the operator tokens and their precedences.
  117.    The value is an integer because, if used, it is the tree code
  118.    to use in the expression made from the operator.  */
  119.  
  120. %right <code> ASSIGN '='
  121. %right <code> '?' ':'
  122. %left <code> OROR
  123. %left <code> ANDAND
  124. %left <code> '|'
  125. %left <code> '^'
  126. %left <code> '&'
  127. %left <code> EQCOMPARE
  128. %left <code> ARITHCOMPARE
  129. %left <code> LSHIFT RSHIFT
  130. %left <code> '+' '-'
  131. %left <code> '*' '/' '%'
  132. %right <code> UNARY PLUSPLUS MINUSMINUS
  133. %left HYPERUNARY
  134. %left <code> POINTSAT '.' '(' '['
  135.  
  136. /* The Objective-C keywords.  These are included in C and in
  137.    Objective C, so that the token codes are the same in both.  */
  138. %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
  139. %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
  140.  
  141. /* Objective-C string constants in raw form.
  142.    yylval is an OBJC_STRING_CST node.  */
  143. %token OBJC_STRING
  144.  
  145.  
  146. %type <code> unop
  147.  
  148. %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
  149. %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
  150. %type <ttype> typed_declspecs reserved_declspecs
  151. %type <ttype> typed_typespecs reserved_typespecquals
  152. %type <ttype> declmods typespec typespecqual_reserved
  153. %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
  154. %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
  155. %type <ttype> init maybeasm
  156. %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
  157. %type <ttype> maybe_attribute attributes attribute attribute_list attrib
  158. %type <ttype> any_word
  159.  
  160. %type <ttype> compstmt
  161.  
  162. %type <ttype> declarator
  163. %type <ttype> notype_declarator after_type_declarator
  164. %type <ttype> parm_declarator
  165.  
  166. %type <ttype> structsp component_decl_list component_decl_list2
  167. %type <ttype> component_decl components component_declarator
  168. %type <ttype> enumlist enumerator
  169. %type <ttype> typename absdcl absdcl1 type_quals
  170. %type <ttype> xexpr parms parm identifiers
  171.  
  172. %type <ttype> parmlist parmlist_1 parmlist_2
  173. %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
  174. %type <ttype> identifiers_or_typenames
  175.  
  176. %type <itype> setspecs
  177.  
  178. %type <filename> save_filename
  179. %type <lineno> save_lineno
  180.  
  181. /* the Objective-C nonterminals */
  182.  
  183. %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
  184. %type <ttype> methoddecl unaryselector keywordselector selector
  185. %type <ttype> keyworddecl receiver objcmessageexpr messageargs
  186. %type <ttype> keywordexpr keywordarglist keywordarg
  187. %type <ttype> myparms myparm optparmlist reservedwords objcselectorexpr
  188. %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
  189. %type <ttype> objc_string protocolrefs identifier_list objcprotocolexpr
  190. %type <ttype> CLASSNAME OBJC_STRING OBJECTNAME
  191.  
  192. %{
  193. /* Number of statements (loosely speaking) seen so far.  */
  194. static int stmt_count;
  195.  
  196. /* Input file and line number of the end of the body of last simple_if;
  197.    used by the stmt-rule immediately after simple_if returns.  */
  198. static char *if_stmt_file;
  199. static int if_stmt_line;
  200.  
  201. /* List of types and structure classes of the current declaration.  */
  202. static tree current_declspecs;
  203. static tree prefix_attributes = NULL_TREE;
  204.  
  205. /* Stack of saved values of current_declspecs and prefix_attributes.  */
  206. static tree declspec_stack;
  207.  
  208. /* 1 if we explained undeclared var errors.  */
  209. static int undeclared_variable_notice;
  210.  
  211. /* Objective-C specific information */
  212.  
  213. tree objc_interface_context;
  214. tree objc_implementation_context;
  215. tree objc_method_context;
  216. tree objc_ivar_chain;
  217. tree objc_ivar_context;
  218. enum tree_code objc_inherit_code;
  219. int objc_receiver_context;
  220. int objc_public_flag;
  221.  
  222.  
  223. /* Tell yyparse how to print a token's value, if yydebug is set.  */
  224.  
  225. #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
  226. extern void yyprint ();
  227. %}
  228.  
  229. %%
  230. program: /* empty */
  231.         { if (pedantic)
  232.             pedwarn ("ANSI C forbids an empty source file");
  233.           finish_file ();
  234.         }
  235.     | extdefs
  236.         {
  237.           /* In case there were missing closebraces,
  238.              get us back to the global binding level.  */
  239.           while (! global_bindings_p ())
  240.             poplevel (0, 0, 0);
  241.           finish_file ();
  242.         }
  243.     ;
  244.  
  245. /* the reason for the strange actions in this rule
  246.  is so that notype_initdecls when reached via datadef
  247.  can find a valid list of type and sc specs in $0. */
  248.  
  249. extdefs:
  250.     {$<ttype>$ = NULL_TREE; } extdef
  251.     | extdefs {$<ttype>$ = NULL_TREE; } extdef
  252.     ;
  253.  
  254. extdef:
  255.     fndef
  256.     | datadef
  257.     | objcdef
  258.     | ASM_KEYWORD '(' expr ')' ';'
  259.         { STRIP_NOPS ($3);
  260.           if ((TREE_CODE ($3) == ADDR_EXPR
  261.                && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
  262.               || TREE_CODE ($3) == STRING_CST)
  263.             assemble_asm ($3);
  264.           else
  265.             error ("argument of `asm' is not a constant string"); }
  266.     ;
  267.  
  268. datadef:
  269.       setspecs notype_initdecls ';'
  270.         { if (pedantic)
  271.             error ("ANSI C forbids data definition with no type or storage class");
  272.           else if (!flag_traditional)
  273.             warning ("data definition has no type or storage class"); 
  274.  
  275.           current_declspecs = TREE_VALUE (declspec_stack);
  276.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  277.           declspec_stack = TREE_CHAIN (declspec_stack);
  278.           resume_momentary ($1); }
  279.         | declmods setspecs notype_initdecls ';'
  280.         { current_declspecs = TREE_VALUE (declspec_stack);
  281.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  282.           declspec_stack = TREE_CHAIN (declspec_stack);
  283.           resume_momentary ($2); }
  284.     | typed_declspecs setspecs initdecls ';'
  285.         { current_declspecs = TREE_VALUE (declspec_stack);
  286.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  287.           declspec_stack = TREE_CHAIN (declspec_stack);
  288.           resume_momentary ($2);  }
  289.         | declmods ';'
  290.       { pedwarn ("empty declaration"); }
  291.     | typed_declspecs ';'
  292.       { shadow_tag ($1); }
  293.     | error ';'
  294.     | error '}'
  295.     | ';'
  296.         { if (pedantic)
  297.             pedwarn ("ANSI C does not allow extra `;' outside of a function"); }
  298.     ;
  299.  
  300. fndef:
  301.       typed_declspecs setspecs declarator
  302.         { if (! start_function ($1, $3, prefix_attributes,
  303.                     NULL_TREE, 0))
  304.             YYERROR1;
  305.           reinit_parse_for_function (); }
  306.       xdecls
  307.         { store_parm_decls (); }
  308.       compstmt_or_error
  309.         { finish_function (0); 
  310.           current_declspecs = TREE_VALUE (declspec_stack);
  311.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  312.           declspec_stack = TREE_CHAIN (declspec_stack);
  313.           resume_momentary ($2); }
  314.     | typed_declspecs setspecs declarator error
  315.         { current_declspecs = TREE_VALUE (declspec_stack);
  316.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  317.           declspec_stack = TREE_CHAIN (declspec_stack);
  318.           resume_momentary ($2); }
  319.     | declmods setspecs notype_declarator
  320.         { if (! start_function ($1, $3, prefix_attributes,
  321.                     NULL_TREE, 0))
  322.             YYERROR1;
  323.           reinit_parse_for_function (); }
  324.       xdecls
  325.         { store_parm_decls (); }
  326.       compstmt_or_error
  327.         { finish_function (0); 
  328.           current_declspecs = TREE_VALUE (declspec_stack);
  329.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  330.           declspec_stack = TREE_CHAIN (declspec_stack);
  331.           resume_momentary ($2); }
  332.     | declmods setspecs notype_declarator error
  333.         { current_declspecs = TREE_VALUE (declspec_stack);
  334.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  335.           declspec_stack = TREE_CHAIN (declspec_stack);
  336.           resume_momentary ($2); }
  337.     | setspecs notype_declarator
  338.         { if (! start_function (NULL_TREE, $2,
  339.                     prefix_attributes, NULL_TREE, 0))
  340.             YYERROR1;
  341.           reinit_parse_for_function (); }
  342.       xdecls
  343.         { store_parm_decls (); }
  344.       compstmt_or_error
  345.         { finish_function (0); 
  346.           current_declspecs = TREE_VALUE (declspec_stack);
  347.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  348.           declspec_stack = TREE_CHAIN (declspec_stack);
  349.           resume_momentary ($1); }
  350.     | setspecs notype_declarator error
  351.         { current_declspecs = TREE_VALUE (declspec_stack);
  352.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  353.           declspec_stack = TREE_CHAIN (declspec_stack);
  354.           resume_momentary ($1); }
  355.     ;
  356.  
  357. identifier:
  358.     IDENTIFIER
  359.     | TYPENAME
  360.     | OBJECTNAME
  361.         | CLASSNAME
  362.     ;
  363.  
  364. unop:     '&'
  365.         { $$ = ADDR_EXPR; }
  366.     | '-'
  367.         { $$ = NEGATE_EXPR; }
  368.     | '+'
  369.         { $$ = CONVERT_EXPR; }
  370.     | PLUSPLUS
  371.         { $$ = PREINCREMENT_EXPR; }
  372.     | MINUSMINUS
  373.         { $$ = PREDECREMENT_EXPR; }
  374.     | '~'
  375.         { $$ = BIT_NOT_EXPR; }
  376.     | '!'
  377.         { $$ = TRUTH_NOT_EXPR; }
  378.     ;
  379.  
  380. expr:    nonnull_exprlist
  381.         { $$ = build_compound_expr ($1); }
  382.     ;
  383.  
  384. exprlist:
  385.       /* empty */
  386.         { $$ = NULL_TREE; }
  387.     | nonnull_exprlist
  388.     ;
  389.  
  390. nonnull_exprlist:
  391.     expr_no_commas
  392.         { $$ = build_tree_list (NULL_TREE, $1); }
  393.     | nonnull_exprlist ',' expr_no_commas
  394.         { chainon ($1, build_tree_list (NULL_TREE, $3)); }
  395.     ;
  396.  
  397. unary_expr:
  398.     primary
  399.     | '*' cast_expr   %prec UNARY
  400.         { $$ = build_indirect_ref ($2, "unary *"); }
  401.     /* __extension__ turns off -pedantic for following primary.  */
  402.     | EXTENSION
  403.         { $<itype>1 = pedantic;
  404.           pedantic = 0; }
  405.       cast_expr      %prec UNARY
  406.         { $$ = $3;
  407.           pedantic = $<itype>1; }
  408.     | unop cast_expr  %prec UNARY
  409.         { $$ = build_unary_op ($1, $2, 0);
  410.           overflow_warning ($$); }
  411.     /* Refer to the address of a label as a pointer.  */
  412.     | ANDAND identifier
  413.         { tree label = lookup_label ($2);
  414.           if (pedantic)
  415.             pedwarn ("ANSI C forbids `&&'");
  416.           if (label == 0)
  417.             $$ = null_pointer_node;
  418.           else
  419.             {
  420.               TREE_USED (label) = 1;
  421.               $$ = build1 (ADDR_EXPR, ptr_type_node, label);
  422.               TREE_CONSTANT ($$) = 1;
  423.             }
  424.         }
  425. /* This seems to be impossible on some machines, so let's turn it off.
  426.    You can use __builtin_next_arg to find the anonymous stack args.
  427.     | '&' ELLIPSIS
  428.         { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
  429.           $$ = error_mark_node;
  430.           if (TREE_VALUE (tree_last (types)) == void_type_node)
  431.             error ("`&...' used in function with fixed number of arguments");
  432.           else
  433.             {
  434.               if (pedantic)
  435.             pedwarn ("ANSI C forbids `&...'");
  436.               $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
  437.               $$ = build_unary_op (ADDR_EXPR, $$, 0);
  438.             } }
  439. */
  440.     | SIZEOF unary_expr  %prec UNARY
  441.         { if (TREE_CODE ($2) == COMPONENT_REF
  442.               && DECL_BIT_FIELD (TREE_OPERAND ($2, 1)))
  443.             error ("`sizeof' applied to a bit-field");
  444.           $$ = c_sizeof (TREE_TYPE ($2)); }
  445.     | SIZEOF '(' typename ')'  %prec HYPERUNARY
  446.         { $$ = c_sizeof (groktypename ($3)); }
  447.     | ALIGNOF unary_expr  %prec UNARY
  448.         { $$ = c_alignof_expr ($2); }
  449.     | ALIGNOF '(' typename ')'  %prec HYPERUNARY
  450.         { $$ = c_alignof (groktypename ($3)); }
  451.     | REALPART cast_expr %prec UNARY
  452.         { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
  453.     | IMAGPART cast_expr %prec UNARY
  454.         { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
  455.     ;
  456.  
  457. cast_expr:
  458.     unary_expr
  459.     | '(' typename ')' cast_expr  %prec UNARY
  460.         { tree type = groktypename ($2);
  461.           $$ = build_c_cast (type, $4); }
  462.     | '(' typename ')' '{' 
  463.         { start_init (NULL_TREE, NULL, 0);
  464.           $2 = groktypename ($2);
  465.           really_start_incremental_init ($2); }
  466.       initlist_maybe_comma '}'  %prec UNARY
  467.         { char *name;
  468.           tree result = pop_init_level (0);
  469.           tree type = $2;
  470.           finish_init ();
  471.  
  472.           if (pedantic)
  473.             pedwarn ("ANSI C forbids constructor expressions");
  474.           if (TYPE_NAME (type) != 0)
  475.             {
  476.               if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  477.             name = IDENTIFIER_POINTER (TYPE_NAME (type));
  478.               else
  479.             name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
  480.             }
  481.           else
  482.             name = "";
  483.           $$ = result;
  484.           if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
  485.             {
  486.               int failure = complete_array_type (type, $$, 1);
  487.               if (failure)
  488.             abort ();
  489.             }
  490.         }
  491.     ;
  492.  
  493. expr_no_commas:
  494.       cast_expr
  495.     | expr_no_commas '+' expr_no_commas
  496.         { $$ = parser_build_binary_op ($2, $1, $3); }
  497.     | expr_no_commas '-' expr_no_commas
  498.         { $$ = parser_build_binary_op ($2, $1, $3); }
  499.     | expr_no_commas '*' expr_no_commas
  500.         { $$ = parser_build_binary_op ($2, $1, $3); }
  501.     | expr_no_commas '/' expr_no_commas
  502.         { $$ = parser_build_binary_op ($2, $1, $3); }
  503.     | expr_no_commas '%' expr_no_commas
  504.         { $$ = parser_build_binary_op ($2, $1, $3); }
  505.     | expr_no_commas LSHIFT expr_no_commas
  506.         { $$ = parser_build_binary_op ($2, $1, $3); }
  507.     | expr_no_commas RSHIFT expr_no_commas
  508.         { $$ = parser_build_binary_op ($2, $1, $3); }
  509.     | expr_no_commas ARITHCOMPARE expr_no_commas
  510.         { $$ = parser_build_binary_op ($2, $1, $3); }
  511.     | expr_no_commas EQCOMPARE expr_no_commas
  512.         { $$ = parser_build_binary_op ($2, $1, $3); }
  513.     | expr_no_commas '&' expr_no_commas
  514.         { $$ = parser_build_binary_op ($2, $1, $3); }
  515.     | expr_no_commas '|' expr_no_commas
  516.         { $$ = parser_build_binary_op ($2, $1, $3); }
  517.     | expr_no_commas '^' expr_no_commas
  518.         { $$ = parser_build_binary_op ($2, $1, $3); }
  519.     | expr_no_commas ANDAND expr_no_commas
  520.         { $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $3); }
  521.     | expr_no_commas OROR expr_no_commas
  522.         { $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $3); }
  523.     | expr_no_commas '?' xexpr ':' expr_no_commas
  524.         { $$ = build_conditional_expr ($1, $3, $5); }
  525.     | expr_no_commas '=' expr_no_commas
  526.         { $$ = build_modify_expr ($1, NOP_EXPR, $3);
  527.           C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
  528.     | expr_no_commas ASSIGN expr_no_commas
  529.         { $$ = build_modify_expr ($1, $2, $3);
  530.           /* This inhibits warnings in truthvalue_conversion.  */
  531.           C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK); }
  532.     ;
  533.  
  534. primary:
  535.     IDENTIFIER
  536.         {
  537.           $$ = lastiddecl;
  538.           if (!$$ || $$ == error_mark_node)
  539.             {
  540.               if (yychar == YYEMPTY)
  541.             yychar = YYLEX;
  542.               if (yychar == '(')
  543.             {
  544.               tree decl;
  545.  
  546.               if (objc_receiver_context
  547.                   && ! (objc_receiver_context
  548.                     && strcmp (IDENTIFIER_POINTER ($1), "super")))
  549.                 /* we have a message to super */
  550.                 $$ = get_super_receiver ();
  551.               else if (objc_method_context
  552.                    && (decl = is_ivar (objc_ivar_chain, $1)))
  553.                 {
  554.                   if (is_private (decl))
  555.                 $$ = error_mark_node;
  556.                   else
  557.                 $$ = build_ivar_reference ($1);
  558.                 }
  559.               else
  560.                 {
  561.                   /* Ordinary implicit function declaration.  */
  562.                   $$ = implicitly_declare ($1);
  563.                   assemble_external ($$);
  564.                   TREE_USED ($$) = 1;
  565.                 }
  566.             }
  567.               else if (current_function_decl == 0)
  568.             {
  569.               error ("`%s' undeclared here (not in a function)",
  570.                  IDENTIFIER_POINTER ($1));
  571.               $$ = error_mark_node;
  572.             }
  573.               else
  574.             {
  575.               tree decl;
  576.  
  577.                   if (objc_receiver_context
  578.                   && ! strcmp (IDENTIFIER_POINTER ($1), "super"))
  579.                 /* we have a message to super */
  580.                 $$ = get_super_receiver ();
  581.               else if (objc_method_context
  582.                    && (decl = is_ivar (objc_ivar_chain, $1)))
  583.                 {
  584.                   if (is_private (decl))
  585.                 $$ = error_mark_node;
  586.                   else
  587.                 $$ = build_ivar_reference ($1);
  588.                 }
  589.               else
  590.                 {
  591.                   if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
  592.                   || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
  593.                 {
  594.                   error ("`%s' undeclared (first use this function)",
  595.                      IDENTIFIER_POINTER ($1));
  596.  
  597.                   if (! undeclared_variable_notice)
  598.                     {
  599.                       error ("(Each undeclared identifier is reported only once");
  600.                       error ("for each function it appears in.)");
  601.                       undeclared_variable_notice = 1;
  602.                     }
  603.                 }
  604.                   $$ = error_mark_node;
  605.                   /* Prevent repeated error messages.  */
  606.                   IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
  607.                   IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
  608.                 }
  609.             }
  610.             }
  611.           else if (TREE_TYPE ($$) == error_mark_node)
  612.             $$ = error_mark_node;
  613.           else if (C_DECL_ANTICIPATED ($$))
  614.             {
  615.               /* The first time we see a build-in function used,
  616.              if it has not been declared.  */
  617.               C_DECL_ANTICIPATED ($$) = 0;
  618.               if (yychar == YYEMPTY)
  619.             yychar = YYLEX;
  620.               if (yychar == '(')
  621.             {
  622.               /* Omit the implicit declaration we
  623.                  would ordinarily do, so we don't lose
  624.                  the actual built in type.
  625.                  But print a diagnostic for the mismatch.  */
  626.               if (objc_method_context
  627.                   && is_ivar (objc_ivar_chain, $1))
  628.                 error ("Instance variable `%s' implicitly declared as function",
  629.                    IDENTIFIER_POINTER (DECL_NAME ($$)));
  630.               else
  631.                 if (TREE_CODE ($$) != FUNCTION_DECL)
  632.                   error ("`%s' implicitly declared as function",
  633.                      IDENTIFIER_POINTER (DECL_NAME ($$)));
  634.               else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$)))
  635.                     != TYPE_MODE (integer_type_node))
  636.                    && (TREE_TYPE (TREE_TYPE ($$))
  637.                        != void_type_node))
  638.                 pedwarn ("type mismatch in implicit declaration for built-in function `%s'",
  639.                      IDENTIFIER_POINTER (DECL_NAME ($$)));
  640.               /* If it really returns void, change that to int.  */
  641.               if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node)
  642.                 TREE_TYPE ($$)
  643.                   = build_function_type (integer_type_node,
  644.                              TYPE_ARG_TYPES (TREE_TYPE ($$)));
  645.             }
  646.               else
  647.             pedwarn ("built-in function `%s' used without declaration",
  648.                  IDENTIFIER_POINTER (DECL_NAME ($$)));
  649.  
  650.               /* Do what we would ordinarily do when a fn is used.  */
  651.               assemble_external ($$);
  652.               TREE_USED ($$) = 1;
  653.             }
  654.           else
  655.             {
  656.               assemble_external ($$);
  657.               TREE_USED ($$) = 1;
  658.               /* we have a definition - still check if iVariable */
  659.  
  660.               if (!objc_receiver_context
  661.               || (objc_receiver_context
  662.                   && strcmp (IDENTIFIER_POINTER ($1), "super")))
  663.                         {
  664.               tree decl;
  665.  
  666.               if (objc_method_context
  667.                   && (decl = is_ivar (objc_ivar_chain, $1)))
  668.                             {
  669.                               if (IDENTIFIER_LOCAL_VALUE ($1))
  670.                                 warning ("local declaration of `%s' hides instance variable",
  671.                                      IDENTIFIER_POINTER ($1));
  672.                               else
  673.                  {
  674.                    if (is_private (decl))
  675.                      $$ = error_mark_node;
  676.                    else
  677.                      $$ = build_ivar_reference ($1);
  678.                  }
  679.                             }
  680.             }
  681.                       else /* we have a message to super */
  682.                 $$ = get_super_receiver ();
  683.             }
  684.  
  685.           if (TREE_CODE ($$) == CONST_DECL)
  686.             {
  687.               $$ = DECL_INITIAL ($$);
  688.               /* This is to prevent an enum whose value is 0
  689.              from being considered a null pointer constant.  */
  690.               $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
  691.               TREE_CONSTANT ($$) = 1;
  692.             }
  693.         }
  694.     | CONSTANT
  695.     | string
  696.         { $$ = combine_strings ($1); }
  697.     | '(' expr ')'
  698.         { char class = TREE_CODE_CLASS (TREE_CODE ($2));
  699.           if (class == 'e' || class == '1'
  700.               || class == '2' || class == '<')
  701.             C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
  702.           $$ = $2; }
  703.     | '(' error ')'
  704.         { $$ = error_mark_node; }
  705.     | '('
  706.         { if (current_function_decl == 0)
  707.             {
  708.               error ("braced-group within expression allowed only inside a function");
  709.               YYERROR;
  710.             }
  711.           /* We must force a BLOCK for this level
  712.              so that, if it is not expanded later,
  713.              there is a way to turn off the entire subtree of blocks
  714.              that are contained in it.  */
  715.           keep_next_level ();
  716.           push_iterator_stack ();
  717.           push_label_level ();
  718.           $<ttype>$ = expand_start_stmt_expr (); }
  719.       compstmt ')'
  720.         { tree rtl_exp;
  721.           if (pedantic)
  722.             pedwarn ("ANSI C forbids braced-groups within expressions");
  723.           pop_iterator_stack ();
  724.           pop_label_level ();
  725.           rtl_exp = expand_end_stmt_expr ($<ttype>2);
  726.           /* The statements have side effects, so the group does.  */
  727.           TREE_SIDE_EFFECTS (rtl_exp) = 1;
  728.  
  729.           if (TREE_CODE ($3) == BLOCK)
  730.             {
  731.               /* Make a BIND_EXPR for the BLOCK already made.  */
  732.               $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
  733.                   NULL_TREE, rtl_exp, $3);
  734.               /* Remove the block from the tree at this point.
  735.              It gets put back at the proper place
  736.              when the BIND_EXPR is expanded.  */
  737.               delete_block ($3);
  738.             }
  739.           else
  740.             $$ = $3;
  741.         }
  742.     | primary '(' exprlist ')'   %prec '.'
  743.         { $$ = build_function_call ($1, $3); }
  744.     | primary '[' expr ']'   %prec '.'
  745.         { $$ = build_array_ref ($1, $3); }
  746.     | primary '.' identifier
  747.         {
  748.                   if (doing_objc_thang)
  749.                     {
  750.               if (is_public ($1, $3))
  751.             $$ = build_component_ref ($1, $3);
  752.               else
  753.             $$ = error_mark_node;
  754.             }
  755.                   else
  756.             $$ = build_component_ref ($1, $3);
  757.         }
  758.     | primary POINTSAT identifier
  759.         {
  760.                   tree expr = build_indirect_ref ($1, "->");
  761.  
  762.                   if (doing_objc_thang)
  763.                     {
  764.               if (is_public (expr, $3))
  765.             $$ = build_component_ref (expr, $3);
  766.               else
  767.             $$ = error_mark_node;
  768.             }
  769.                   else
  770.                     $$ = build_component_ref (expr, $3);
  771.         }
  772.     | primary PLUSPLUS
  773.         { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
  774.     | primary MINUSMINUS
  775.         { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
  776.     | objcmessageexpr
  777.         { $$ = build_message_expr ($1); }
  778.     | objcselectorexpr
  779.         { $$ = build_selector_expr ($1); }
  780.     | objcprotocolexpr
  781.         { $$ = build_protocol_expr ($1); }
  782.     | objcencodeexpr
  783.         { $$ = build_encode_expr ($1); }
  784.     | objc_string
  785.         { $$ = build_objc_string_object ($1); }
  786.     ;
  787.  
  788. /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it.  */
  789. string:
  790.       STRING
  791.     | string STRING
  792.         { $$ = chainon ($1, $2); }
  793.     ;
  794.  
  795. /* Produces an OBJC_STRING_CST with perhaps more OBJC_STRING_CSTs chained
  796.    onto it.  */
  797. objc_string:
  798.       OBJC_STRING
  799.     | objc_string OBJC_STRING
  800.         { $$ = chainon ($1, $2); }
  801.     ;
  802.  
  803. xdecls:
  804.     /* empty */
  805.     | datadecls
  806.     | datadecls ELLIPSIS
  807.         /* ... is used here to indicate a varargs function.  */
  808.         { c_mark_varargs ();
  809.           if (pedantic)
  810.             pedwarn ("ANSI C does not permit use of `varargs.h'"); }
  811.     ;
  812.  
  813. /* The following are analogous to lineno_decl, decls and decl
  814.    except that they do not allow nested functions.
  815.    They are used for old-style parm decls.  */
  816. lineno_datadecl:
  817.       save_filename save_lineno datadecl
  818.         { }
  819.     ;
  820.  
  821. datadecls:
  822.     lineno_datadecl
  823.     | errstmt
  824.     | datadecls lineno_datadecl
  825.     | lineno_datadecl errstmt
  826.     ;
  827.  
  828. datadecl:
  829.     typed_declspecs setspecs initdecls ';'
  830.         { current_declspecs = TREE_VALUE (declspec_stack);
  831.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  832.           declspec_stack = TREE_CHAIN (declspec_stack);
  833.           resume_momentary ($2); }
  834.     | declmods setspecs notype_initdecls ';'
  835.         { current_declspecs = TREE_VALUE (declspec_stack);    
  836.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  837.           declspec_stack = TREE_CHAIN (declspec_stack);
  838.           resume_momentary ($2); }
  839.     | typed_declspecs ';'
  840.         { shadow_tag_warned ($1, 1);
  841.           pedwarn ("empty declaration"); }
  842.     | declmods ';'
  843.         { pedwarn ("empty declaration"); }
  844.     ;
  845.  
  846. /* This combination which saves a lineno before a decl
  847.    is the normal thing to use, rather than decl itself.
  848.    This is to avoid shift/reduce conflicts in contexts
  849.    where statement labels are allowed.  */
  850. lineno_decl:
  851.       save_filename save_lineno decl
  852.         { }
  853.     ;
  854.  
  855. decls:
  856.     lineno_decl
  857.     | errstmt
  858.     | decls lineno_decl
  859.     | lineno_decl errstmt
  860.     ;
  861.  
  862. /* records the type and storage class specs to use for processing
  863.    the declarators that follow.
  864.    Maintains a stack of outer-level values of current_declspecs,
  865.    for the sake of parm declarations nested in function declarators.  */
  866. setspecs: /* empty */
  867.         { $$ = suspend_momentary ();
  868.           pending_xref_error ();
  869.           declspec_stack = tree_cons (prefix_attributes,
  870.                           current_declspecs,
  871.                           declspec_stack);
  872.           current_declspecs = $<ttype>0; 
  873.           prefix_attributes = NULL_TREE; }
  874.     ;
  875.  
  876. setattrs: /* empty */
  877.         { prefix_attributes = chainon (prefix_attributes, $<ttype>0); }
  878.     ;
  879.  
  880. decl:
  881.     typed_declspecs setspecs initdecls ';'
  882.         { current_declspecs = TREE_VALUE (declspec_stack);
  883.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  884.           declspec_stack = TREE_CHAIN (declspec_stack);
  885.           resume_momentary ($2); }
  886.     | declmods setspecs notype_initdecls ';'
  887.         { current_declspecs = TREE_VALUE (declspec_stack);
  888.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  889.           declspec_stack = TREE_CHAIN (declspec_stack);
  890.           resume_momentary ($2); }
  891.     | typed_declspecs setspecs nested_function
  892.         { current_declspecs = TREE_VALUE (declspec_stack);
  893.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  894.           declspec_stack = TREE_CHAIN (declspec_stack);
  895.           resume_momentary ($2); }
  896.     | declmods setspecs notype_nested_function
  897.         { current_declspecs = TREE_VALUE (declspec_stack);
  898.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  899.           declspec_stack = TREE_CHAIN (declspec_stack);
  900.           resume_momentary ($2); }
  901.     | typed_declspecs ';'
  902.         { shadow_tag ($1); }
  903.     | declmods ';'
  904.         { pedwarn ("empty declaration"); }
  905.     ;
  906.  
  907. /* Declspecs which contain at least one type specifier or typedef name.
  908.    (Just `const' or `volatile' is not enough.)
  909.    A typedef'd name following these is taken as a name to be declared.  */
  910.  
  911. typed_declspecs:
  912.       typespec reserved_declspecs
  913.         { $$ = tree_cons (NULL_TREE, $1, $2); }
  914.     | declmods typespec reserved_declspecs
  915.         { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
  916.     ;
  917.  
  918. reserved_declspecs:  /* empty */
  919.         { $$ = NULL_TREE; }
  920.     | reserved_declspecs typespecqual_reserved
  921.         { $$ = tree_cons (NULL_TREE, $2, $1); }
  922.     | reserved_declspecs SCSPEC
  923.         { if (extra_warnings)
  924.             warning ("`%s' is not at beginning of declaration",
  925.                  IDENTIFIER_POINTER ($2));
  926.           $$ = tree_cons (NULL_TREE, $2, $1); }
  927.     ;
  928.  
  929. /* List of just storage classes and type modifiers.
  930.    A declaration can start with just this, but then it cannot be used
  931.    to redeclare a typedef-name.  */
  932.  
  933. declmods:
  934.       TYPE_QUAL
  935.         { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
  936.           TREE_STATIC ($$) = 1; }
  937.     | SCSPEC
  938.         { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
  939.     | declmods TYPE_QUAL
  940.         { $$ = tree_cons (NULL_TREE, $2, $1);
  941.           TREE_STATIC ($$) = 1; }
  942.     | declmods SCSPEC
  943.         { if (extra_warnings && TREE_STATIC ($1))
  944.             warning ("`%s' is not at beginning of declaration",
  945.                  IDENTIFIER_POINTER ($2));
  946.           $$ = tree_cons (NULL_TREE, $2, $1);
  947.           TREE_STATIC ($$) = TREE_STATIC ($1); }
  948.     ;
  949.  
  950.  
  951. /* Used instead of declspecs where storage classes are not allowed
  952.    (that is, for typenames and structure components).
  953.    Don't accept a typedef-name if anything but a modifier precedes it.  */
  954.  
  955. typed_typespecs:
  956.       typespec reserved_typespecquals
  957.         { $$ = tree_cons (NULL_TREE, $1, $2); }
  958.     | nonempty_type_quals typespec reserved_typespecquals
  959.         { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
  960.     ;
  961.  
  962. reserved_typespecquals:  /* empty */
  963.         { $$ = NULL_TREE; }
  964.     | reserved_typespecquals typespecqual_reserved
  965.         { $$ = tree_cons (NULL_TREE, $2, $1); }
  966.     ;
  967.  
  968. /* A typespec (but not a type qualifier).
  969.    Once we have seen one of these in a declaration,
  970.    if a typedef name appears then it is being redeclared.  */
  971.  
  972. typespec: TYPESPEC
  973.     | structsp
  974.     | TYPENAME
  975.         { /* For a typedef name, record the meaning, not the name.
  976.              In case of `foo foo, bar;'.  */
  977.           $$ = lookup_name ($1); }
  978.     | CLASSNAME protocolrefs
  979.         { $$ = get_static_reference ($1, $2); }
  980.     | OBJECTNAME protocolrefs
  981.         { $$ = get_object_reference ($2); }
  982.     | TYPEOF '(' expr ')'
  983.         { $$ = TREE_TYPE ($3); }
  984.     | TYPEOF '(' typename ')'
  985.         { $$ = groktypename ($3); }
  986.     ;
  987.  
  988. /* A typespec that is a reserved word, or a type qualifier.  */
  989.  
  990. typespecqual_reserved: TYPESPEC
  991.     | TYPE_QUAL
  992.     | structsp
  993.     ;
  994.  
  995. initdecls:
  996.     initdcl
  997.     | initdecls ',' initdcl
  998.     ;
  999.  
  1000. notype_initdecls:
  1001.     notype_initdcl
  1002.     | notype_initdecls ',' initdcl
  1003.     ;
  1004.  
  1005. maybeasm:
  1006.       /* empty */
  1007.         { $$ = NULL_TREE; }
  1008.     | ASM_KEYWORD '(' string ')'
  1009.         { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
  1010.           $$ = $3;
  1011.         }
  1012.     ;
  1013.  
  1014. initdcl:
  1015.       declarator maybeasm maybe_attribute '='
  1016.         { $<ttype>$ = start_decl ($1, current_declspecs, 1,
  1017.                       $3, prefix_attributes);
  1018.           start_init ($<ttype>$, $2, global_bindings_p ()); }
  1019.       init
  1020. /* Note how the declaration of the variable is in effect while its init is parsed! */
  1021.         { finish_init ();
  1022.           finish_decl ($<ttype>5, $6, $2); }
  1023.     | declarator maybeasm maybe_attribute
  1024.         { tree d = start_decl ($1, current_declspecs, 0,
  1025.                        $3, prefix_attributes);
  1026.           finish_decl (d, NULL_TREE, $2); 
  1027.                 }
  1028.     ;
  1029.  
  1030. notype_initdcl:
  1031.       notype_declarator maybeasm maybe_attribute '='
  1032.         { $<ttype>$ = start_decl ($1, current_declspecs, 1,
  1033.                       $3, prefix_attributes);
  1034.           start_init ($<ttype>$, $2, global_bindings_p ()); }
  1035.       init
  1036. /* Note how the declaration of the variable is in effect while its init is parsed! */
  1037.         { finish_init ();
  1038.           decl_attributes ($<ttype>5, $3, prefix_attributes);
  1039.           finish_decl ($<ttype>5, $6, $2); }
  1040.     | notype_declarator maybeasm maybe_attribute
  1041.         { tree d = start_decl ($1, current_declspecs, 0,
  1042.                        $3, prefix_attributes);
  1043.           finish_decl (d, NULL_TREE, $2); }
  1044.     ;
  1045. /* the * rules are dummies to accept the Apollo extended syntax
  1046.    so that the header files compile. */
  1047. maybe_attribute:
  1048.       /* empty */
  1049.           { $$ = NULL_TREE; }
  1050.     | attributes
  1051.         { $$ = $1; }
  1052.     ;
  1053.  
  1054. attributes:
  1055.       attribute
  1056.         { $$ = $1; }
  1057.     | attributes attribute
  1058.         { $$ = chainon ($1, $2); }
  1059.     ;
  1060.  
  1061. attribute:
  1062.       ATTRIBUTE '(' '(' attribute_list ')' ')'
  1063.         { $$ = $4; }
  1064.     ;
  1065.  
  1066. attribute_list:
  1067.       attrib
  1068.         { $$ = $1; }
  1069.     | attribute_list ',' attrib
  1070.         { $$ = chainon ($1, $3); }
  1071.     ;
  1072.  
  1073. attrib:
  1074.     /* empty */
  1075.         { $$ = NULL_TREE; }
  1076.     | any_word
  1077.         { $$ = build_tree_list ($1, NULL_TREE); }
  1078.     | any_word '(' IDENTIFIER ')'
  1079.         { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
  1080.     | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
  1081.         { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
  1082.     | any_word '(' exprlist ')'
  1083.         { $$ = build_tree_list ($1, $3); }
  1084.     ;
  1085.  
  1086. /* This still leaves out most reserved keywords,
  1087.    shouldn't we include them?  */
  1088.  
  1089. any_word:
  1090.       identifier
  1091.     | SCSPEC
  1092.     | TYPESPEC
  1093.     | TYPE_QUAL
  1094.     ;
  1095.  
  1096. /* Initializers.  `init' is the entry point.  */
  1097.  
  1098. init:
  1099.     expr_no_commas
  1100.     | '{'
  1101.         { really_start_incremental_init (NULL_TREE);
  1102.           /* Note that the call to clear_momentary
  1103.              is in process_init_element.  */
  1104.           push_momentary (); }
  1105.       initlist_maybe_comma '}'
  1106.         { $$ = pop_init_level (0);
  1107.           if ($$ == error_mark_node
  1108.               && ! (yychar == STRING || yychar == CONSTANT))
  1109.             pop_momentary ();
  1110.           else
  1111.             pop_momentary_nofree (); }
  1112.  
  1113.     | error
  1114.         { $$ = error_mark_node; }
  1115.     ;
  1116.  
  1117. /* `initlist_maybe_comma' is the guts of an initializer in braces.  */
  1118. initlist_maybe_comma:
  1119.       /* empty */
  1120.         { if (pedantic)
  1121.             pedwarn ("ANSI C forbids empty initializer braces"); }
  1122.     | initlist1 maybecomma
  1123.     ;
  1124.  
  1125. initlist1:
  1126.       initelt
  1127.     | initlist1 ',' initelt
  1128.     ;
  1129.  
  1130. /* `initelt' is a single element of an initializer.
  1131.    It may use braces.  */
  1132. initelt:
  1133.     expr_no_commas
  1134.         { process_init_element ($1); }
  1135.     | '{' 
  1136.         { push_init_level (0); }
  1137.       initlist_maybe_comma '}'
  1138.         { process_init_element (pop_init_level (0)); }
  1139.     | error
  1140.     /* These are for labeled elements.  The syntax for an array element
  1141.        initializer conflicts with the syntax for an Objective-C message,
  1142.        so don't include these productions in the Objective-C grammar.  */
  1143.     | identifier ':'
  1144.         { set_init_label ($1); }
  1145.       initelt
  1146.     | '.' identifier '='
  1147.         { set_init_label ($2); }
  1148.       initelt
  1149.     ;
  1150.  
  1151. nested_function:
  1152.       declarator
  1153.         { push_c_function_context ();
  1154.           if (! start_function (current_declspecs, $1,
  1155.                     prefix_attributes, NULL_TREE, 1))
  1156.             {
  1157.               pop_c_function_context ();
  1158.               YYERROR1;
  1159.             }
  1160.           reinit_parse_for_function (); }
  1161.        xdecls
  1162.         { store_parm_decls (); }
  1163. /* This used to use compstmt_or_error.
  1164.    That caused a bug with input `f(g) int g {}',
  1165.    where the use of YYERROR1 above caused an error
  1166.    which then was handled by compstmt_or_error.
  1167.    There followed a repeated execution of that same rule,
  1168.    which called YYERROR1 again, and so on.  */
  1169.       compstmt
  1170.         { finish_function (1);
  1171.           pop_c_function_context (); }
  1172.     ;
  1173.  
  1174. notype_nested_function:
  1175.       notype_declarator
  1176.         { push_c_function_context ();
  1177.           if (! start_function (current_declspecs, $1,
  1178.                     prefix_attributes, NULL_TREE, 1))
  1179.             {
  1180.               pop_c_function_context ();
  1181.               YYERROR1;
  1182.             }
  1183.           reinit_parse_for_function (); }
  1184.       xdecls
  1185.         { store_parm_decls (); }
  1186. /* This used to use compstmt_or_error.
  1187.    That caused a bug with input `f(g) int g {}',
  1188.    where the use of YYERROR1 above caused an error
  1189.    which then was handled by compstmt_or_error.
  1190.    There followed a repeated execution of that same rule,
  1191.    which called YYERROR1 again, and so on.  */
  1192.       compstmt
  1193.         { finish_function (1);
  1194.           pop_c_function_context (); }
  1195.     ;
  1196.  
  1197. /* Any kind of declarator (thus, all declarators allowed
  1198.    after an explicit typespec).  */
  1199.  
  1200. declarator:
  1201.       after_type_declarator
  1202.     | notype_declarator
  1203.     ;
  1204.  
  1205. /* A declarator that is allowed only after an explicit typespec.  */
  1206.  
  1207. after_type_declarator:
  1208.       '(' after_type_declarator ')'
  1209.         { $$ = $2; }
  1210.     | after_type_declarator '(' parmlist_or_identifiers  %prec '.'
  1211.         { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
  1212. /*    | after_type_declarator '(' error ')'  %prec '.'
  1213.         { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
  1214.           poplevel (0, 0, 0); }  */
  1215.     | after_type_declarator '[' expr ']'  %prec '.'
  1216.         { $$ = build_nt (ARRAY_REF, $1, $3); }
  1217.     | after_type_declarator '[' ']'  %prec '.'
  1218.         { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
  1219.     | '*' type_quals after_type_declarator  %prec UNARY
  1220.         { $$ = make_pointer_declarator ($2, $3); }
  1221.     | attributes setattrs after_type_declarator
  1222.         { $$ = $3; }
  1223.     | TYPENAME
  1224.     | OBJECTNAME
  1225.     ;
  1226.  
  1227. /* Kinds of declarator that can appear in a parameter list
  1228.    in addition to notype_declarator.  This is like after_type_declarator
  1229.    but does not allow a typedef name in parentheses as an identifier
  1230.    (because it would conflict with a function with that typedef as arg).  */
  1231.  
  1232. parm_declarator:
  1233.       parm_declarator '(' parmlist_or_identifiers  %prec '.'
  1234.         { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
  1235. /*    | parm_declarator '(' error ')'  %prec '.'
  1236.         { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
  1237.           poplevel (0, 0, 0); }  */
  1238.     | parm_declarator '[' expr ']'  %prec '.'
  1239.         { $$ = build_nt (ARRAY_REF, $1, $3); }
  1240.     | parm_declarator '[' ']'  %prec '.'
  1241.         { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
  1242.     | '*' type_quals parm_declarator  %prec UNARY
  1243.         { $$ = make_pointer_declarator ($2, $3); }
  1244.     | attributes setattrs parm_declarator
  1245.         { $$ = $3; }
  1246.     | TYPENAME
  1247.     ;
  1248.  
  1249. /* A declarator allowed whether or not there has been
  1250.    an explicit typespec.  These cannot redeclare a typedef-name.  */
  1251.  
  1252. notype_declarator:
  1253.       notype_declarator '(' parmlist_or_identifiers  %prec '.'
  1254.         { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
  1255. /*    | notype_declarator '(' error ')'  %prec '.'
  1256.         { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
  1257.           poplevel (0, 0, 0); }  */
  1258.     | '(' notype_declarator ')'
  1259.         { $$ = $2; }
  1260.     | '*' type_quals notype_declarator  %prec UNARY
  1261.         { $$ = make_pointer_declarator ($2, $3); }
  1262.     | notype_declarator '[' expr ']'  %prec '.'
  1263.         { $$ = build_nt (ARRAY_REF, $1, $3); }
  1264.     | notype_declarator '[' ']'  %prec '.'
  1265.         { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
  1266.     | attributes setattrs notype_declarator
  1267.         { $$ = $3; }
  1268.     | IDENTIFIER
  1269.     ;
  1270.  
  1271. structsp:
  1272.       STRUCT identifier '{'
  1273.         { $$ = start_struct (RECORD_TYPE, $2);
  1274.           /* Start scope of tag before parsing components.  */
  1275.         }
  1276.       component_decl_list '}' maybe_attribute 
  1277.         { $$ = finish_struct ($<ttype>4, $5, $7); }
  1278.     | STRUCT '{' component_decl_list '}' maybe_attribute
  1279.         { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
  1280.                       $3, $5);
  1281.         }
  1282.     | STRUCT identifier
  1283.         { $$ = xref_tag (RECORD_TYPE, $2); }
  1284.     | UNION identifier '{'
  1285.         { $$ = start_struct (UNION_TYPE, $2); }
  1286.       component_decl_list '}' maybe_attribute
  1287.         { $$ = finish_struct ($<ttype>4, $5, $7); }
  1288.     | UNION '{' component_decl_list '}' maybe_attribute
  1289.         { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
  1290.                       $3, $5);
  1291.         }
  1292.     | UNION identifier
  1293.         { $$ = xref_tag (UNION_TYPE, $2); }
  1294.     | ENUM identifier '{'
  1295.         { $<itype>3 = suspend_momentary ();
  1296.           $$ = start_enum ($2); }
  1297.       enumlist maybecomma_warn '}' maybe_attribute
  1298.         { $$ = finish_enum ($<ttype>4, nreverse ($5), $8);
  1299.           resume_momentary ($<itype>3); }
  1300.     | ENUM '{'
  1301.         { $<itype>2 = suspend_momentary ();
  1302.           $$ = start_enum (NULL_TREE); }
  1303.       enumlist maybecomma_warn '}' maybe_attribute
  1304.         { $$ = finish_enum ($<ttype>3, nreverse ($4), $7);
  1305.           resume_momentary ($<itype>2); }
  1306.     | ENUM identifier
  1307.         { $$ = xref_tag (ENUMERAL_TYPE, $2); }
  1308.     ;
  1309.  
  1310. maybecomma:
  1311.       /* empty */
  1312.     | ','
  1313.     ;
  1314.  
  1315. maybecomma_warn:
  1316.       /* empty */
  1317.     | ','
  1318.         { if (pedantic) pedwarn ("comma at end of enumerator list"); }
  1319.     ;
  1320.  
  1321. component_decl_list:
  1322.       component_decl_list2
  1323.         { $$ = $1; }
  1324.     | component_decl_list2 component_decl
  1325.         { $$ = chainon ($1, $2);
  1326.           pedwarn ("no semicolon at end of struct or union"); }
  1327.     ;
  1328.  
  1329. component_decl_list2:    /* empty */
  1330.         { $$ = NULL_TREE; }
  1331.     | component_decl_list2 component_decl ';'
  1332.         { $$ = chainon ($1, $2); }
  1333.     | component_decl_list2 ';'
  1334.         { if (pedantic)
  1335.             pedwarn ("extra semicolon in struct or union specified"); }
  1336.     /* foo(sizeof(struct{ @defs(ClassName)})); */
  1337.     | DEFS '(' CLASSNAME ')'
  1338.         {
  1339.           tree interface = lookup_interface ($3);
  1340.  
  1341.           if (interface)
  1342.             $$ = get_class_ivars (interface);
  1343.           else
  1344.             {
  1345.               error ("Cannot find interface declaration for `%s'",
  1346.                  IDENTIFIER_POINTER ($3));
  1347.               $$ = NULL_TREE;
  1348.             }
  1349.         }
  1350.     ;
  1351.  
  1352. /* There is a shift-reduce conflict here, because `components' may
  1353.    start with a `typename'.  It happens that shifting (the default resolution)
  1354.    does the right thing, because it treats the `typename' as part of
  1355.    a `typed_typespecs'.
  1356.  
  1357.    It is possible that this same technique would allow the distinction
  1358.    between `notype_initdecls' and `initdecls' to be eliminated.
  1359.    But I am being cautious and not trying it.  */
  1360.  
  1361. component_decl:
  1362.       typed_typespecs setspecs components
  1363.         { $$ = $3;
  1364.           current_declspecs = TREE_VALUE (declspec_stack);
  1365.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  1366.           declspec_stack = TREE_CHAIN (declspec_stack);
  1367.           resume_momentary ($2); }
  1368.     | typed_typespecs
  1369.         { if (pedantic)
  1370.             pedwarn ("ANSI C forbids member declarations with no members");
  1371.           shadow_tag($1);
  1372.           $$ = NULL_TREE; }
  1373.     | nonempty_type_quals setspecs components
  1374.         { $$ = $3;
  1375.           current_declspecs = TREE_VALUE (declspec_stack);
  1376.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  1377.           declspec_stack = TREE_CHAIN (declspec_stack);
  1378.           resume_momentary ($2); }
  1379.     | nonempty_type_quals
  1380.         { if (pedantic)
  1381.             pedwarn ("ANSI C forbids member declarations with no members");
  1382.           shadow_tag($1);
  1383.           $$ = NULL_TREE; }
  1384.     | error
  1385.         { $$ = NULL_TREE; }
  1386.     ;
  1387.  
  1388. components:
  1389.       component_declarator
  1390.     | components ',' component_declarator
  1391.         { $$ = chainon ($1, $3); }
  1392.     ;
  1393.  
  1394. component_declarator:
  1395.       save_filename save_lineno declarator maybe_attribute
  1396.         { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
  1397.           decl_attributes ($$, $4, prefix_attributes); }
  1398.     | save_filename save_lineno
  1399.       declarator ':' expr_no_commas maybe_attribute
  1400.         { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
  1401.           decl_attributes ($$, $6, prefix_attributes); }
  1402.     | save_filename save_lineno ':' expr_no_commas maybe_attribute
  1403.         { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
  1404.           decl_attributes ($$, $5, prefix_attributes); }
  1405.     ;
  1406.  
  1407. /* We chain the enumerators in reverse order.
  1408.    They are put in forward order where enumlist is used.
  1409.    (The order used to be significant, but no longer is so.
  1410.    However, we still maintain the order, just to be clean.)  */
  1411.  
  1412. enumlist:
  1413.       enumerator
  1414.     | enumlist ',' enumerator
  1415.         { $$ = chainon ($3, $1); }
  1416.     | error
  1417.         { $$ = error_mark_node; }
  1418.     ;
  1419.  
  1420.  
  1421. enumerator:
  1422.       identifier
  1423.         { $$ = build_enumerator ($1, NULL_TREE); }
  1424.     | identifier '=' expr_no_commas
  1425.         { $$ = build_enumerator ($1, $3); }
  1426.     ;
  1427.  
  1428. typename:
  1429.     typed_typespecs absdcl
  1430.         { $$ = build_tree_list ($1, $2); }
  1431.     | nonempty_type_quals absdcl
  1432.         { $$ = build_tree_list ($1, $2); }
  1433.     ;
  1434.  
  1435. absdcl:   /* an absolute declarator */
  1436.     /* empty */
  1437.         { $$ = NULL_TREE; }
  1438.     | absdcl1
  1439.     ;
  1440.  
  1441. nonempty_type_quals:
  1442.       TYPE_QUAL
  1443.         { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
  1444.     | nonempty_type_quals TYPE_QUAL
  1445.         { $$ = tree_cons (NULL_TREE, $2, $1); }
  1446.     ;
  1447.  
  1448. type_quals:
  1449.       /* empty */
  1450.         { $$ = NULL_TREE; }
  1451.     | type_quals TYPE_QUAL
  1452.         { $$ = tree_cons (NULL_TREE, $2, $1); }
  1453.     ;
  1454.  
  1455. absdcl1:  /* a nonempty absolute declarator */
  1456.       '(' absdcl1 ')'
  1457.         { $$ = $2; }
  1458.       /* `(typedef)1' is `int'.  */
  1459.     | '*' type_quals absdcl1  %prec UNARY
  1460.         { $$ = make_pointer_declarator ($2, $3); }
  1461.     | '*' type_quals  %prec UNARY
  1462.         { $$ = make_pointer_declarator ($2, NULL_TREE); }
  1463.     | absdcl1 '(' parmlist  %prec '.'
  1464.         { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
  1465.     | absdcl1 '[' expr ']'  %prec '.'
  1466.         { $$ = build_nt (ARRAY_REF, $1, $3); }
  1467.     | absdcl1 '[' ']'  %prec '.'
  1468.         { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
  1469.     | '(' parmlist  %prec '.'
  1470.         { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
  1471.     | '[' expr ']'  %prec '.'
  1472.         { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
  1473.     | '[' ']'  %prec '.'
  1474.         { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
  1475.     | attributes setattrs absdcl1
  1476.         { $$ = $3; }
  1477.     ;
  1478.  
  1479. /* at least one statement, the first of which parses without error.  */
  1480. /* stmts is used only after decls, so an invalid first statement
  1481.    is actually regarded as an invalid decl and part of the decls.  */
  1482.  
  1483. stmts:
  1484.       lineno_stmt_or_label
  1485.     | stmts lineno_stmt_or_label
  1486.     | stmts errstmt
  1487.     ;
  1488.  
  1489. xstmts:
  1490.     /* empty */
  1491.     | stmts
  1492.     ;
  1493.  
  1494. errstmt:  error ';'
  1495.     ;
  1496.  
  1497. pushlevel:  /* empty */
  1498.         { emit_line_note (input_filename, lineno);
  1499.           pushlevel (0);
  1500.           clear_last_expr ();
  1501.           push_momentary ();
  1502.           expand_start_bindings (0);
  1503.           if (objc_method_context)
  1504.             add_objc_decls ();
  1505.         }
  1506.     ;
  1507.  
  1508. /* Read zero or more forward-declarations for labels
  1509.    that nested functions can jump to.  */
  1510. maybe_label_decls:
  1511.       /* empty */
  1512.     | label_decls
  1513.         { if (pedantic)
  1514.             pedwarn ("ANSI C forbids label declarations"); }
  1515.     ;
  1516.  
  1517. label_decls:
  1518.       label_decl
  1519.     | label_decls label_decl
  1520.     ;
  1521.  
  1522. label_decl:
  1523.       LABEL identifiers_or_typenames ';'
  1524.         { tree link;
  1525.           for (link = $2; link; link = TREE_CHAIN (link))
  1526.             {
  1527.               tree label = shadow_label (TREE_VALUE (link));
  1528.               C_DECLARED_LABEL_FLAG (label) = 1;
  1529.               declare_nonlocal_label (label);
  1530.             }
  1531.         }
  1532.     ;
  1533.  
  1534. /* This is the body of a function definition.
  1535.    It causes syntax errors to ignore to the next openbrace.  */
  1536. compstmt_or_error:
  1537.       compstmt
  1538.         {}
  1539.     | error compstmt
  1540.     ;
  1541.  
  1542. compstmt: '{' '}'
  1543.         { $$ = convert (void_type_node, integer_zero_node); }
  1544.     | '{' pushlevel maybe_label_decls decls xstmts '}'
  1545.         { emit_line_note (input_filename, lineno);
  1546.           expand_end_bindings (getdecls (), 1, 0);
  1547.           $$ = poplevel (1, 1, 0);
  1548.           if (yychar == CONSTANT || yychar == STRING)
  1549.             pop_momentary_nofree ();
  1550.           else
  1551.             pop_momentary (); }
  1552.     | '{' pushlevel maybe_label_decls error '}'
  1553.         { emit_line_note (input_filename, lineno);
  1554.           expand_end_bindings (getdecls (), kept_level_p (), 0);
  1555.           $$ = poplevel (kept_level_p (), 0, 0);
  1556.           if (yychar == CONSTANT || yychar == STRING)
  1557.             pop_momentary_nofree ();
  1558.           else
  1559.             pop_momentary (); }
  1560.     | '{' pushlevel maybe_label_decls stmts '}'
  1561.         { emit_line_note (input_filename, lineno);
  1562.           expand_end_bindings (getdecls (), kept_level_p (), 0);
  1563.           $$ = poplevel (kept_level_p (), 0, 0);
  1564.           if (yychar == CONSTANT || yychar == STRING)
  1565.             pop_momentary_nofree ();
  1566.           else
  1567.             pop_momentary (); }
  1568.     ;
  1569.  
  1570. /* Value is number of statements counted as of the closeparen.  */
  1571. simple_if:
  1572.       if_prefix lineno_labeled_stmt
  1573. /* Make sure expand_end_cond is run once
  1574.    for each call to expand_start_cond.
  1575.    Otherwise a crash is likely.  */
  1576.     | if_prefix error
  1577.     ;
  1578.  
  1579. if_prefix:
  1580.       IF '(' expr ')'
  1581.         { emit_line_note ($<filename>-1, $<lineno>0);
  1582.           expand_start_cond (truthvalue_conversion ($3), 0);
  1583.           $<itype>$ = stmt_count;
  1584.           if_stmt_file = $<filename>-1;
  1585.           if_stmt_line = $<lineno>0;
  1586.           position_after_white_space (); }
  1587.     ;
  1588.  
  1589. /* This is a subroutine of stmt.
  1590.    It is used twice, once for valid DO statements
  1591.    and once for catching errors in parsing the end test.  */
  1592. do_stmt_start:
  1593.       DO
  1594.         { stmt_count++;
  1595.           emit_line_note ($<filename>-1, $<lineno>0);
  1596.           /* See comment in `while' alternative, above.  */
  1597.           emit_nop ();
  1598.           expand_start_loop_continue_elsewhere (1);
  1599.           position_after_white_space (); }
  1600.       lineno_labeled_stmt WHILE
  1601.         { expand_loop_continue_here (); }
  1602.     ;
  1603.  
  1604. save_filename:
  1605.         { $$ = input_filename; }
  1606.     ;
  1607.  
  1608. save_lineno:
  1609.         { $$ = lineno; }
  1610.     ;
  1611.  
  1612. lineno_labeled_stmt:
  1613.       save_filename save_lineno stmt
  1614.         { }
  1615. /*    | save_filename save_lineno error
  1616.         { }
  1617. */
  1618.     | save_filename save_lineno label lineno_labeled_stmt
  1619.         { }
  1620.     ;
  1621.  
  1622. lineno_stmt_or_label:
  1623.       save_filename save_lineno stmt_or_label
  1624.         { }
  1625.     ;
  1626.  
  1627. stmt_or_label:
  1628.       stmt
  1629.     | label
  1630.         { int next;
  1631.           position_after_white_space ();
  1632.           next = getc (finput);
  1633.           ungetc (next, finput);
  1634.           if (pedantic && next == '}')
  1635.             pedwarn ("ANSI C forbids label at end of compound statement");
  1636.         }
  1637.     ;
  1638.  
  1639. /* Parse a single real statement, not including any labels.  */
  1640. stmt:
  1641.       compstmt
  1642.         { stmt_count++; }
  1643.         | all_iter_stmt 
  1644.     | expr ';'
  1645.         { stmt_count++;
  1646.           emit_line_note ($<filename>-1, $<lineno>0);
  1647. /* It appears that this should not be done--that a non-lvalue array
  1648.    shouldn't get an error if the value isn't used.
  1649.    Section 3.2.2.1 says that an array lvalue gets converted to a pointer
  1650.    if it appears as a top-level expression,
  1651.    but says nothing about non-lvalue arrays.  */
  1652. #if 0
  1653.           /* Call default_conversion to get an error
  1654.              on referring to a register array if pedantic.  */
  1655.           if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
  1656.               || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
  1657.             $1 = default_conversion ($1);
  1658. #endif
  1659.           iterator_expand ($1);
  1660.           clear_momentary (); }
  1661.     | simple_if ELSE
  1662.         { expand_start_else ();
  1663.           $<itype>1 = stmt_count;
  1664.           position_after_white_space (); }
  1665.       lineno_labeled_stmt
  1666.         { expand_end_cond ();
  1667.           if (extra_warnings && stmt_count == $<itype>1)
  1668.             warning ("empty body in an else-statement"); }
  1669.     | simple_if %prec IF
  1670.         { expand_end_cond ();
  1671.           /* This warning is here instead of in simple_if, because we
  1672.              do not want a warning if an empty if is followed by an
  1673.              else statement.  Increment stmt_count so we don't
  1674.              give a second error if this is a nested `if'.  */
  1675.           if (extra_warnings && stmt_count++ == $<itype>1)
  1676.             warning_with_file_and_line (if_stmt_file, if_stmt_line,
  1677.                         "empty body in an if-statement"); }
  1678. /* Make sure expand_end_cond is run once
  1679.    for each call to expand_start_cond.
  1680.    Otherwise a crash is likely.  */
  1681.     | simple_if ELSE error
  1682.         { expand_end_cond (); }
  1683.     | WHILE
  1684.         { stmt_count++;
  1685.           emit_line_note ($<filename>-1, $<lineno>0);
  1686.           /* The emit_nop used to come before emit_line_note,
  1687.              but that made the nop seem like part of the preceding line.
  1688.              And that was confusing when the preceding line was
  1689.              inside of an if statement and was not really executed.
  1690.              I think it ought to work to put the nop after the line number.
  1691.              We will see.  --rms, July 15, 1991.  */
  1692.           emit_nop (); }
  1693.       '(' expr ')'
  1694.         { /* Don't start the loop till we have succeeded
  1695.              in parsing the end test.  This is to make sure
  1696.              that we end every loop we start.  */
  1697.           expand_start_loop (1);
  1698.           emit_line_note (input_filename, lineno);
  1699.           expand_exit_loop_if_false (NULL_PTR,
  1700.                          truthvalue_conversion ($4));
  1701.           position_after_white_space (); }
  1702.       lineno_labeled_stmt
  1703.         { expand_end_loop (); }
  1704.     | do_stmt_start
  1705.       '(' expr ')' ';'
  1706.         { emit_line_note (input_filename, lineno);
  1707.           expand_exit_loop_if_false (NULL_PTR,
  1708.                          truthvalue_conversion ($3));
  1709.           expand_end_loop ();
  1710.           clear_momentary (); }
  1711. /* This rule is needed to make sure we end every loop we start.  */
  1712.     | do_stmt_start error
  1713.         { expand_end_loop ();
  1714.           clear_momentary (); }
  1715.     | FOR
  1716.       '(' xexpr ';'
  1717.         { stmt_count++;
  1718.           emit_line_note ($<filename>-1, $<lineno>0);
  1719.           /* See comment in `while' alternative, above.  */
  1720.           emit_nop ();
  1721.           if ($3) c_expand_expr_stmt ($3);
  1722.           /* Next step is to call expand_start_loop_continue_elsewhere,
  1723.              but wait till after we parse the entire for (...).
  1724.              Otherwise, invalid input might cause us to call that
  1725.              fn without calling expand_end_loop.  */
  1726.         }
  1727.       xexpr ';'
  1728.         /* Can't emit now; wait till after expand_start_loop...  */
  1729.         { $<lineno>7 = lineno;
  1730.           $<filename>$ = input_filename; }
  1731.       xexpr ')'
  1732.         { 
  1733.           /* Start the loop.  Doing this after parsing
  1734.              all the expressions ensures we will end the loop.  */
  1735.           expand_start_loop_continue_elsewhere (1);
  1736.           /* Emit the end-test, with a line number.  */
  1737.           emit_line_note ($<filename>8, $<lineno>7);
  1738.           if ($6)
  1739.             expand_exit_loop_if_false (NULL_PTR,
  1740.                            truthvalue_conversion ($6));
  1741.           /* Don't let the tree nodes for $9 be discarded by
  1742.              clear_momentary during the parsing of the next stmt.  */
  1743.           push_momentary ();
  1744.           $<lineno>7 = lineno;
  1745.           $<filename>8 = input_filename;
  1746.           position_after_white_space (); }
  1747.       lineno_labeled_stmt
  1748.         { /* Emit the increment expression, with a line number.  */
  1749.           emit_line_note ($<filename>8, $<lineno>7);
  1750.           expand_loop_continue_here ();
  1751.           if ($9)
  1752.             c_expand_expr_stmt ($9);
  1753.           if (yychar == CONSTANT || yychar == STRING)
  1754.             pop_momentary_nofree ();
  1755.           else
  1756.             pop_momentary ();
  1757.           expand_end_loop (); }
  1758.     | SWITCH '(' expr ')'
  1759.         { stmt_count++;
  1760.           emit_line_note ($<filename>-1, $<lineno>0);
  1761.           c_expand_start_case ($3);
  1762.           /* Don't let the tree nodes for $3 be discarded by
  1763.              clear_momentary during the parsing of the next stmt.  */
  1764.           push_momentary ();
  1765.           position_after_white_space (); }
  1766.       lineno_labeled_stmt
  1767.         { expand_end_case ($3);
  1768.           if (yychar == CONSTANT || yychar == STRING)
  1769.             pop_momentary_nofree ();
  1770.           else
  1771.             pop_momentary (); }
  1772.     | BREAK ';'
  1773.         { stmt_count++;
  1774.           emit_line_note ($<filename>-1, $<lineno>0);
  1775.           if ( ! expand_exit_something ())
  1776.             error ("break statement not within loop or switch"); }
  1777.     | CONTINUE ';'
  1778.         { stmt_count++;
  1779.           emit_line_note ($<filename>-1, $<lineno>0);
  1780.           if (! expand_continue_loop (NULL_PTR))
  1781.             error ("continue statement not within a loop"); }
  1782.     | RETURN ';'
  1783.         { stmt_count++;
  1784.           emit_line_note ($<filename>-1, $<lineno>0);
  1785.           c_expand_return (NULL_TREE); }
  1786.     | RETURN expr ';'
  1787.         { stmt_count++;
  1788.           emit_line_note ($<filename>-1, $<lineno>0);
  1789.           c_expand_return ($2); }
  1790.     | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
  1791.         { stmt_count++;
  1792.           emit_line_note ($<filename>-1, $<lineno>0);
  1793.           STRIP_NOPS ($4);
  1794.           if ((TREE_CODE ($4) == ADDR_EXPR
  1795.                && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
  1796.               || TREE_CODE ($4) == STRING_CST)
  1797.             expand_asm ($4);
  1798.           else
  1799.             error ("argument of `asm' is not a constant string"); }
  1800.     /* This is the case with just output operands.  */
  1801.     | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
  1802.         { stmt_count++;
  1803.           emit_line_note ($<filename>-1, $<lineno>0);
  1804.           c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
  1805.                      $2 == ridpointers[(int)RID_VOLATILE],
  1806.                      input_filename, lineno); }
  1807.     /* This is the case with input operands as well.  */
  1808.     | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
  1809.         { stmt_count++;
  1810.           emit_line_note ($<filename>-1, $<lineno>0);
  1811.           c_expand_asm_operands ($4, $6, $8, NULL_TREE,
  1812.                      $2 == ridpointers[(int)RID_VOLATILE],
  1813.                      input_filename, lineno); }
  1814.     /* This is the case with clobbered registers as well.  */
  1815.     | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
  1816.         asm_operands ':' asm_clobbers ')' ';'
  1817.         { stmt_count++;
  1818.           emit_line_note ($<filename>-1, $<lineno>0);
  1819.           c_expand_asm_operands ($4, $6, $8, $10,
  1820.                      $2 == ridpointers[(int)RID_VOLATILE],
  1821.                      input_filename, lineno); }
  1822.     | GOTO identifier ';'
  1823.         { tree decl;
  1824.           stmt_count++;
  1825.           emit_line_note ($<filename>-1, $<lineno>0);
  1826.           decl = lookup_label ($2);
  1827.           if (decl != 0)
  1828.             {
  1829.               TREE_USED (decl) = 1;
  1830.               expand_goto (decl);
  1831.             }
  1832.         }
  1833.     | GOTO '*' expr ';'
  1834.         { stmt_count++;
  1835.           emit_line_note ($<filename>-1, $<lineno>0);
  1836.           expand_computed_goto (convert (ptr_type_node, $3)); }
  1837.     | ';'
  1838.     ;
  1839.  
  1840. all_iter_stmt:
  1841.       all_iter_stmt_simple
  1842. /*    | all_iter_stmt_with_decl */
  1843.     ;
  1844.  
  1845. all_iter_stmt_simple:
  1846.       FOR '(' primary ')' 
  1847.       {
  1848.         /* The value returned by this action is  */
  1849.         /*      1 if everything is OK */ 
  1850.         /*      0 in case of error or already bound iterator */
  1851.  
  1852.         $<itype>$ = 0;
  1853.         if (TREE_CODE ($3) != VAR_DECL)
  1854.           error ("invalid `for (ITERATOR)' syntax");
  1855.         else if (! ITERATOR_P ($3))
  1856.           error ("`%s' is not an iterator",
  1857.              IDENTIFIER_POINTER (DECL_NAME ($3)));
  1858.         else if (ITERATOR_BOUND_P ($3))
  1859.           error ("`for (%s)' inside expansion of same iterator",
  1860.              IDENTIFIER_POINTER (DECL_NAME ($3)));
  1861.         else
  1862.           {
  1863.         $<itype>$ = 1;
  1864.         iterator_for_loop_start ($3);
  1865.           }
  1866.       }
  1867.       lineno_labeled_stmt
  1868.       {
  1869.         if ($<itype>5)
  1870.           iterator_for_loop_end ($3);
  1871.       }
  1872.  
  1873. /*  This really should allow any kind of declaration,
  1874.     for generality.  Fix it before turning it back on.
  1875.  
  1876. all_iter_stmt_with_decl:
  1877.       FOR '(' ITERATOR pushlevel setspecs iterator_spec ')' 
  1878.       {
  1879. */        /* The value returned by this action is  */
  1880.         /*      1 if everything is OK */ 
  1881.         /*      0 in case of error or already bound iterator */
  1882. /*
  1883.         iterator_for_loop_start ($6);
  1884.       }
  1885.       lineno_labeled_stmt
  1886.       {
  1887.         iterator_for_loop_end ($6);
  1888.         emit_line_note (input_filename, lineno);
  1889.         expand_end_bindings (getdecls (), 1, 0);
  1890.         $<ttype>$ = poplevel (1, 1, 0);
  1891.         if (yychar == CONSTANT || yychar == STRING)
  1892.           pop_momentary_nofree ();
  1893.         else
  1894.           pop_momentary ();        
  1895.       }
  1896. */
  1897.  
  1898. /* Any kind of label, including jump labels and case labels.
  1899.    ANSI C accepts labels only before statements, but we allow them
  1900.    also at the end of a compound statement.  */
  1901.  
  1902. label:      CASE expr_no_commas ':'
  1903.         { register tree value = check_case_value ($2);
  1904.           register tree label
  1905.             = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  1906.  
  1907.           stmt_count++;
  1908.  
  1909.           if (value != error_mark_node)
  1910.             {
  1911.               tree duplicate;
  1912.               int success = pushcase (value, convert_and_check,
  1913.                           label, &duplicate);
  1914.               if (success == 1)
  1915.             error ("case label not within a switch statement");
  1916.               else if (success == 2)
  1917.             {
  1918.               error ("duplicate case value");
  1919.               error_with_decl (duplicate, "this is the first entry for that value");
  1920.             }
  1921.               else if (success == 3)
  1922.             warning ("case value out of range");
  1923.               else if (success == 5)
  1924.             error ("case label within scope of cleanup or variable array");
  1925.             }
  1926.           position_after_white_space (); }
  1927.     | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
  1928.         { register tree value1 = check_case_value ($2);
  1929.           register tree value2 = check_case_value ($4);
  1930.           register tree label
  1931.             = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  1932.  
  1933.           stmt_count++;
  1934.  
  1935.           if (value1 != error_mark_node && value2 != error_mark_node)
  1936.             {
  1937.               tree duplicate;
  1938.               int success = pushcase_range (value1, value2,
  1939.                             convert_and_check, label,
  1940.                             &duplicate);
  1941.               if (success == 1)
  1942.             error ("case label not within a switch statement");
  1943.               else if (success == 2)
  1944.             {
  1945.               error ("duplicate case value");
  1946.               error_with_decl (duplicate, "this is the first entry for that value");
  1947.             }
  1948.               else if (success == 3)
  1949.             warning ("case value out of range");
  1950.               else if (success == 4)
  1951.             warning ("empty case range");
  1952.               else if (success == 5)
  1953.             error ("case label within scope of cleanup or variable array");
  1954.             }
  1955.           position_after_white_space (); }
  1956.     | DEFAULT ':'
  1957.         {
  1958.           tree duplicate;
  1959.           register tree label
  1960.             = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  1961.           int success = pushcase (NULL_TREE, 0, label, &duplicate);
  1962.           stmt_count++;
  1963.           if (success == 1)
  1964.             error ("default label not within a switch statement");
  1965.           else if (success == 2)
  1966.             {
  1967.               error ("multiple default labels in one switch");
  1968.               error_with_decl (duplicate, "this is the first default label");
  1969.             }
  1970.           position_after_white_space (); }
  1971.     | identifier ':'
  1972.         { tree label = define_label (input_filename, lineno, $1);
  1973.           stmt_count++;
  1974.           emit_nop ();
  1975.           if (label)
  1976.             expand_label (label);
  1977.           position_after_white_space (); }
  1978.     ;
  1979.  
  1980. /* Either a type-qualifier or nothing.  First thing in an `asm' statement.  */
  1981.  
  1982. maybe_type_qual:
  1983.     /* empty */
  1984.         { emit_line_note (input_filename, lineno);
  1985.           $$ = NULL_TREE; }
  1986.     | TYPE_QUAL
  1987.         { emit_line_note (input_filename, lineno); }
  1988.     ;
  1989.  
  1990. xexpr:
  1991.     /* empty */
  1992.         { $$ = NULL_TREE; }
  1993.     | expr
  1994.     ;
  1995.  
  1996. /* These are the operands other than the first string and colon
  1997.    in  asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x))  */
  1998. asm_operands: /* empty */
  1999.         { $$ = NULL_TREE; }
  2000.     | nonnull_asm_operands
  2001.     ;
  2002.  
  2003. nonnull_asm_operands:
  2004.       asm_operand
  2005.     | nonnull_asm_operands ',' asm_operand
  2006.         { $$ = chainon ($1, $3); }
  2007.     ;
  2008.  
  2009. asm_operand:
  2010.       STRING '(' expr ')'
  2011.         { $$ = build_tree_list ($1, $3); }
  2012.     ;
  2013.  
  2014. asm_clobbers:
  2015.       string
  2016.         { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
  2017.     | asm_clobbers ',' string
  2018.         { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
  2019.     ;
  2020.  
  2021. /* This is what appears inside the parens in a function declarator.
  2022.    Its value is a list of ..._TYPE nodes.  */
  2023. parmlist:
  2024.         { pushlevel (0);
  2025.           clear_parm_order ();
  2026.           declare_parm_level (0); }
  2027.       parmlist_1
  2028.         { $$ = $2;
  2029.           parmlist_tags_warning ();
  2030.           poplevel (0, 0, 0); }
  2031.     ;
  2032.  
  2033. parmlist_1:
  2034.       parmlist_2 ')'
  2035.     | parms ';'
  2036.         { tree parm;
  2037.           if (pedantic)
  2038.             pedwarn ("ANSI C forbids forward parameter declarations");
  2039.           /* Mark the forward decls as such.  */
  2040.           for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
  2041.             TREE_ASM_WRITTEN (parm) = 1;
  2042.           clear_parm_order (); }
  2043.       parmlist_1
  2044.         { $$ = $4; }
  2045.     | error ')'
  2046.         { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
  2047.     ;
  2048.  
  2049. /* This is what appears inside the parens in a function declarator.
  2050.    Is value is represented in the format that grokdeclarator expects.  */
  2051. parmlist_2:  /* empty */
  2052.         { $$ = get_parm_info (0); }
  2053.     | ELLIPSIS
  2054.         { $$ = get_parm_info (0);
  2055.           /* Gcc used to allow this as an extension.  However, it does
  2056.              not work for all targets, and thus has been disabled.
  2057.              Also, since func (...) and func () are indistinguishable,
  2058.              it caused problems with the code in expand_builtin which
  2059.              tries to verify that BUILT_IN_NEXT_ARG is being used
  2060.              correctly.  */
  2061.           error ("ANSI C requires a named argument before `...'");
  2062.         }
  2063.     | parms
  2064.         { $$ = get_parm_info (1); }
  2065.     | parms ',' ELLIPSIS
  2066.         { $$ = get_parm_info (0); }
  2067.     ;
  2068.  
  2069. parms:
  2070.     parm
  2071.         { push_parm_decl ($1); }
  2072.     | parms ',' parm
  2073.         { push_parm_decl ($3); }
  2074.     ;
  2075.  
  2076. /* A single parameter declaration or parameter type name,
  2077.    as found in a parmlist.  */
  2078. parm:
  2079.       typed_declspecs setspecs parm_declarator maybe_attribute
  2080.         { $$ = build_tree_list (build_tree_list (current_declspecs,
  2081.                              $3),
  2082.                     build_tree_list (prefix_attributes,
  2083.                              $4));
  2084.           current_declspecs = TREE_VALUE (declspec_stack);
  2085.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  2086.           declspec_stack = TREE_CHAIN (declspec_stack);
  2087.           resume_momentary ($2); }
  2088.     | typed_declspecs setspecs notype_declarator maybe_attribute
  2089.         { $$ = build_tree_list (build_tree_list (current_declspecs,
  2090.                              $3),
  2091.                     build_tree_list (prefix_attributes,
  2092.                              $4)); 
  2093.           current_declspecs = TREE_VALUE (declspec_stack);
  2094.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  2095.           declspec_stack = TREE_CHAIN (declspec_stack);
  2096.           resume_momentary ($2); }
  2097.     | typed_declspecs setspecs absdcl maybe_attribute
  2098.         { $$ = build_tree_list (build_tree_list (current_declspecs,
  2099.                              $3),
  2100.                     build_tree_list (prefix_attributes,
  2101.                              $4));
  2102.           current_declspecs = TREE_VALUE (declspec_stack);
  2103.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  2104.           declspec_stack = TREE_CHAIN (declspec_stack);
  2105.           resume_momentary ($2); }
  2106.     | declmods setspecs notype_declarator maybe_attribute
  2107.         { $$ = build_tree_list (build_tree_list (current_declspecs,
  2108.                              $3),
  2109.                     build_tree_list (prefix_attributes,
  2110.                              $4));
  2111.           current_declspecs = TREE_VALUE (declspec_stack);
  2112.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  2113.           declspec_stack = TREE_CHAIN (declspec_stack);
  2114.           resume_momentary ($2);  }
  2115.  
  2116.     | declmods setspecs absdcl maybe_attribute
  2117.         { $$ = build_tree_list (build_tree_list (current_declspecs,
  2118.                              $3),
  2119.                     build_tree_list (prefix_attributes,
  2120.                              $4));
  2121.           current_declspecs = TREE_VALUE (declspec_stack);
  2122.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  2123.           declspec_stack = TREE_CHAIN (declspec_stack);
  2124.           resume_momentary ($2);  }
  2125.     ;
  2126.  
  2127. /* This is used in a function definition
  2128.    where either a parmlist or an identifier list is ok.
  2129.    Its value is a list of ..._TYPE nodes or a list of identifiers.  */
  2130. parmlist_or_identifiers:
  2131.         { pushlevel (0);
  2132.           clear_parm_order ();
  2133.           declare_parm_level (1); }
  2134.       parmlist_or_identifiers_1
  2135.         { $$ = $2;
  2136.           parmlist_tags_warning ();
  2137.           poplevel (0, 0, 0); }
  2138.     ;
  2139.  
  2140. parmlist_or_identifiers_1:
  2141.       parmlist_1
  2142.     | identifiers ')'
  2143.         { tree t;
  2144.           for (t = $1; t; t = TREE_CHAIN (t))
  2145.             if (TREE_VALUE (t) == NULL_TREE)
  2146.               error ("`...' in old-style identifier list");
  2147.           $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
  2148.     ;
  2149.  
  2150. /* A nonempty list of identifiers.  */
  2151. identifiers:
  2152.     IDENTIFIER
  2153.         { $$ = build_tree_list (NULL_TREE, $1); }
  2154.     | identifiers ',' IDENTIFIER
  2155.         { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
  2156.     ;
  2157.  
  2158. /* A nonempty list of identifiers, including typenames.  */
  2159. identifiers_or_typenames:
  2160.     identifier
  2161.         { $$ = build_tree_list (NULL_TREE, $1); }
  2162.     | identifiers_or_typenames ',' identifier
  2163.         { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
  2164.     ;
  2165.  
  2166. /* Objective-C productions.  */
  2167.  
  2168. objcdef:
  2169.       classdef
  2170.     | classdecl
  2171.     | aliasdecl
  2172.     | protocoldef
  2173.     | methoddef
  2174.     | END
  2175.         {
  2176.           if (objc_implementation_context)
  2177.                     {
  2178.               finish_class (objc_implementation_context);
  2179.               objc_ivar_chain = NULL_TREE;
  2180.               objc_implementation_context = NULL_TREE;
  2181.             }
  2182.           else
  2183.             warning ("`@end' must appear in an implementation context");
  2184.         }
  2185.     ;
  2186.  
  2187. /* A nonempty list of identifiers.  */
  2188. identifier_list:
  2189.     identifier
  2190.         { $$ = build_tree_list (NULL_TREE, $1); }
  2191.     | identifier_list ',' identifier
  2192.         { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
  2193.     ;
  2194.  
  2195. classdecl:
  2196.       CLASS identifier_list ';'
  2197.         {
  2198.           objc_declare_class ($2);
  2199.         }
  2200.  
  2201. aliasdecl:
  2202.       ALIAS identifier identifier ';'
  2203.         {
  2204.           objc_declare_alias ($2, $3);
  2205.         }
  2206.  
  2207. classdef:
  2208.       INTERFACE identifier protocolrefs '{'
  2209.         {
  2210.           objc_interface_context = objc_ivar_context
  2211.             = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
  2212.                   objc_public_flag = 0;
  2213.         }
  2214.       ivar_decl_list '}'
  2215.         {
  2216.                   continue_class (objc_interface_context);
  2217.         }
  2218.       methodprotolist
  2219.       END
  2220.         {
  2221.           finish_class (objc_interface_context);
  2222.           objc_interface_context = NULL_TREE;
  2223.         }
  2224.  
  2225.     | INTERFACE identifier protocolrefs
  2226.         {
  2227.           objc_interface_context
  2228.             = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
  2229.                   continue_class (objc_interface_context);
  2230.         }
  2231.       methodprotolist
  2232.       END
  2233.         {
  2234.           finish_class (objc_interface_context);
  2235.           objc_interface_context = NULL_TREE;
  2236.         }
  2237.  
  2238.     | INTERFACE identifier ':' identifier protocolrefs '{'
  2239.         {
  2240.           objc_interface_context = objc_ivar_context
  2241.             = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
  2242.                   objc_public_flag = 0;
  2243.         }
  2244.       ivar_decl_list '}'
  2245.         {
  2246.                   continue_class (objc_interface_context);
  2247.         }
  2248.       methodprotolist
  2249.       END
  2250.         {
  2251.           finish_class (objc_interface_context);
  2252.           objc_interface_context = NULL_TREE;
  2253.         }
  2254.  
  2255.     | INTERFACE identifier ':' identifier protocolrefs
  2256.         {
  2257.           objc_interface_context
  2258.             = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
  2259.                   continue_class (objc_interface_context);
  2260.         }
  2261.       methodprotolist
  2262.       END
  2263.         {
  2264.           finish_class (objc_interface_context);
  2265.           objc_interface_context = NULL_TREE;
  2266.         }
  2267.  
  2268.     | IMPLEMENTATION identifier '{'
  2269.         {
  2270.           objc_implementation_context = objc_ivar_context
  2271.             = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
  2272.                   objc_public_flag = 0;
  2273.         }
  2274.       ivar_decl_list '}'
  2275.         {
  2276.                   objc_ivar_chain
  2277.             = continue_class (objc_implementation_context);
  2278.         }
  2279.  
  2280.     | IMPLEMENTATION identifier
  2281.         {
  2282.           objc_implementation_context
  2283.             = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
  2284.                   objc_ivar_chain
  2285.             = continue_class (objc_implementation_context);
  2286.         }
  2287.  
  2288.     | IMPLEMENTATION identifier ':' identifier '{'
  2289.         {
  2290.           objc_implementation_context = objc_ivar_context
  2291.             = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
  2292.                   objc_public_flag = 0;
  2293.         }
  2294.       ivar_decl_list '}'
  2295.         {
  2296.                   objc_ivar_chain
  2297.             = continue_class (objc_implementation_context);
  2298.         }
  2299.  
  2300.     | IMPLEMENTATION identifier ':' identifier
  2301.         {
  2302.           objc_implementation_context
  2303.             = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
  2304.                   objc_ivar_chain
  2305.             = continue_class (objc_implementation_context);
  2306.         }
  2307.  
  2308.     | INTERFACE identifier '(' identifier ')' protocolrefs
  2309.         {
  2310.           objc_interface_context
  2311.             = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6);
  2312.                   continue_class (objc_interface_context);
  2313.         }
  2314.       methodprotolist
  2315.       END
  2316.         {
  2317.           finish_class (objc_interface_context);
  2318.           objc_interface_context = NULL_TREE;
  2319.         }
  2320.  
  2321.     | IMPLEMENTATION identifier '(' identifier ')'
  2322.         {
  2323.           objc_implementation_context
  2324.             = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
  2325.                   objc_ivar_chain
  2326.             = continue_class (objc_implementation_context);
  2327.         }
  2328.     ;
  2329.  
  2330. protocoldef:
  2331.       PROTOCOL identifier protocolrefs
  2332.         {
  2333.           remember_protocol_qualifiers ();
  2334.           objc_interface_context
  2335.             = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3);
  2336.         }
  2337.       methodprotolist END
  2338.         {
  2339.           forget_protocol_qualifiers();
  2340.           finish_protocol(objc_interface_context);
  2341.           objc_interface_context = NULL_TREE;
  2342.         }
  2343.     ;
  2344.  
  2345. protocolrefs:
  2346.       /* empty */
  2347.         {
  2348.           $$ = NULL_TREE;
  2349.         }
  2350.     | ARITHCOMPARE identifier_list ARITHCOMPARE
  2351.         {
  2352.           if ($1 == LT_EXPR && $3 == GT_EXPR)
  2353.             $$ = $2;
  2354.           else
  2355.             YYERROR1;
  2356.         }
  2357.     ;
  2358.  
  2359. ivar_decl_list:
  2360.           ivar_decl_list visibility_spec ivar_decls
  2361.         | ivar_decls
  2362.         ;
  2363.  
  2364. visibility_spec:
  2365.       PRIVATE { objc_public_flag = 2; }
  2366.     | PROTECTED { objc_public_flag = 0; }
  2367.     | PUBLIC { objc_public_flag = 1; }
  2368.     ;
  2369.  
  2370. ivar_decls:
  2371.           /* empty */
  2372.         {
  2373.                   $$ = NULL_TREE;
  2374.                 }
  2375.     | ivar_decls ivar_decl ';'
  2376.     | ivar_decls ';'
  2377.         {
  2378.                   if (pedantic)
  2379.             pedwarn ("extra semicolon in struct or union specified");
  2380.                 }
  2381.     ;
  2382.  
  2383.  
  2384. /* There is a shift-reduce conflict here, because `components' may
  2385.    start with a `typename'.  It happens that shifting (the default resolution)
  2386.    does the right thing, because it treats the `typename' as part of
  2387.    a `typed_typespecs'.
  2388.  
  2389.    It is possible that this same technique would allow the distinction
  2390.    between `notype_initdecls' and `initdecls' to be eliminated.
  2391.    But I am being cautious and not trying it.  */
  2392.  
  2393. ivar_decl:
  2394.     typed_typespecs setspecs ivars
  2395.             { $$ = $3;
  2396.           current_declspecs = TREE_VALUE (declspec_stack);
  2397.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  2398.           declspec_stack = TREE_CHAIN (declspec_stack);
  2399.           resume_momentary ($2); }
  2400.     | nonempty_type_quals setspecs ivars
  2401.         { $$ = $3;
  2402.           current_declspecs = TREE_VALUE (declspec_stack);
  2403.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  2404.           declspec_stack = TREE_CHAIN (declspec_stack);
  2405.           resume_momentary ($2); }
  2406.     | error
  2407.         { $$ = NULL_TREE; }
  2408.     ;
  2409.  
  2410. ivars:
  2411.       /* empty */
  2412.         { $$ = NULL_TREE; }
  2413.     | ivar_declarator
  2414.     | ivars ',' ivar_declarator
  2415.     ;
  2416.  
  2417. ivar_declarator:
  2418.       declarator
  2419.         {
  2420.           $$ = add_instance_variable (objc_ivar_context,
  2421.                           objc_public_flag,
  2422.                           $1, current_declspecs,
  2423.                           NULL_TREE);
  2424.                 }
  2425.     | declarator ':' expr_no_commas
  2426.         {
  2427.           $$ = add_instance_variable (objc_ivar_context,
  2428.                           objc_public_flag,
  2429.                           $1, current_declspecs, $3);
  2430.                 }
  2431.     | ':' expr_no_commas
  2432.         {
  2433.           $$ = add_instance_variable (objc_ivar_context,
  2434.                           objc_public_flag,
  2435.                           NULL_TREE,
  2436.                           current_declspecs, $2);
  2437.                 }
  2438.     ;
  2439.  
  2440. methoddef:
  2441.       '+'
  2442.         {
  2443.           remember_protocol_qualifiers ();
  2444.           if (objc_implementation_context)
  2445.             objc_inherit_code = CLASS_METHOD_DECL;
  2446.                   else
  2447.             fatal ("method definition not in class context");
  2448.         }
  2449.       methoddecl
  2450.         {
  2451.           forget_protocol_qualifiers ();
  2452.           add_class_method (objc_implementation_context, $3);
  2453.           start_method_def ($3);
  2454.           objc_method_context = $3;
  2455.         }
  2456.       optarglist
  2457.         {
  2458.           continue_method_def ();
  2459.         }
  2460.       compstmt_or_error
  2461.         {
  2462.           finish_method_def ();
  2463.           objc_method_context = NULL_TREE;
  2464.         }
  2465.  
  2466.     | '-'
  2467.         {
  2468.           remember_protocol_qualifiers ();
  2469.           if (objc_implementation_context)
  2470.             objc_inherit_code = INSTANCE_METHOD_DECL;
  2471.                   else
  2472.             fatal ("method definition not in class context");
  2473.         }
  2474.       methoddecl
  2475.         {
  2476.           forget_protocol_qualifiers ();
  2477.           add_instance_method (objc_implementation_context, $3);
  2478.           start_method_def ($3);
  2479.           objc_method_context = $3;
  2480.         }
  2481.       optarglist
  2482.         {
  2483.           continue_method_def ();
  2484.         }
  2485.       compstmt_or_error
  2486.         {
  2487.           finish_method_def ();
  2488.           objc_method_context = NULL_TREE;
  2489.         }
  2490.     ;
  2491.  
  2492. /* the reason for the strange actions in this rule
  2493.  is so that notype_initdecls when reached via datadef
  2494.  can find a valid list of type and sc specs in $0. */
  2495.  
  2496. methodprotolist:
  2497.       /* empty  */
  2498.     | {$<ttype>$ = NULL_TREE; } methodprotolist2
  2499.     ;
  2500.  
  2501. methodprotolist2:         /* eliminates a shift/reduce conflict */
  2502.        methodproto
  2503.     |  datadef
  2504.     | methodprotolist2 methodproto
  2505.     | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
  2506.     ;
  2507.  
  2508. semi_or_error:
  2509.       ';'
  2510.     | error
  2511.     ;
  2512.  
  2513. methodproto:
  2514.       '+'
  2515.         {
  2516.           objc_inherit_code = CLASS_METHOD_DECL;
  2517.         }
  2518.       methoddecl
  2519.         {
  2520.           add_class_method (objc_interface_context, $3);
  2521.         }
  2522.       semi_or_error
  2523.  
  2524.     | '-'
  2525.         {
  2526.           objc_inherit_code = INSTANCE_METHOD_DECL;
  2527.         }
  2528.       methoddecl
  2529.         {
  2530.           add_instance_method (objc_interface_context, $3);
  2531.         }
  2532.       semi_or_error
  2533.     ;
  2534.  
  2535. methoddecl:
  2536.       '(' typename ')' unaryselector
  2537.         {
  2538.           $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
  2539.         }
  2540.  
  2541.     | unaryselector
  2542.         {
  2543.           $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
  2544.         }
  2545.  
  2546.     | '(' typename ')' keywordselector optparmlist
  2547.         {
  2548.           $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
  2549.         }
  2550.  
  2551.     | keywordselector optparmlist
  2552.         {
  2553.           $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
  2554.         }
  2555.     ;
  2556.  
  2557. /* "optarglist" assumes that start_method_def has already been called...
  2558.    if it is not, the "xdecls" will not be placed in the proper scope */
  2559.  
  2560. optarglist:
  2561.       /* empty */
  2562.     | ';' myxdecls
  2563.     ;
  2564.  
  2565. /* to get around the following situation: "int foo (int a) int b; {}" that
  2566.    is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
  2567.  
  2568. myxdecls:
  2569.       /* empty */
  2570.     | mydecls
  2571.     ;
  2572.  
  2573. mydecls:
  2574.     mydecl
  2575.     | errstmt
  2576.     | mydecls mydecl
  2577.     | mydecl errstmt
  2578.     ;
  2579.  
  2580. mydecl:
  2581.     typed_declspecs setspecs myparms ';'
  2582.         { current_declspecs = TREE_VALUE (declspec_stack);
  2583.           prefix_attributes = TREE_PURPOSE (declspec_stack);
  2584.           declspec_stack = TREE_CHAIN (declspec_stack);
  2585.           resume_momentary ($2); }
  2586.     | typed_declspecs ';'
  2587.         { shadow_tag ($1); }
  2588.     | declmods ';'
  2589.         { pedwarn ("empty declaration"); }
  2590.     ;
  2591.  
  2592. myparms:
  2593.     myparm
  2594.         { push_parm_decl ($1); }
  2595.     | myparms ',' myparm
  2596.         { push_parm_decl ($3); }
  2597.     ;
  2598.  
  2599. /* A single parameter declaration or parameter type name,
  2600.    as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
  2601.  
  2602. myparm:
  2603.       parm_declarator maybe_attribute
  2604.         { $$ = build_tree_list (build_tree_list (current_declspecs,
  2605.                              $1),
  2606.                     build_tree_list (prefix_attributes,
  2607.                              $2)); }
  2608.     | notype_declarator maybe_attribute
  2609.         { $$ = build_tree_list (build_tree_list (current_declspecs,
  2610.                              $1),
  2611.                     build_tree_list (prefix_attributes,
  2612.                              $2)); }
  2613.     | absdcl maybe_attribute
  2614.         { $$ = build_tree_list (build_tree_list (current_declspecs,
  2615.                              $1),
  2616.                     build_tree_list (prefix_attributes,
  2617.                              $2)); }
  2618.     ;
  2619.  
  2620. optparmlist:
  2621.       /* empty */
  2622.         {
  2623.               $$ = NULL_TREE;
  2624.         }
  2625.     | ',' ELLIPSIS
  2626.         {
  2627.           /* oh what a kludge! */
  2628.           $$ = (tree)1;
  2629.         }
  2630.     | ','
  2631.         {
  2632.           pushlevel (0);
  2633.         }
  2634.       parmlist_2
  2635.         {
  2636.             /* returns a tree list node generated by get_parm_info */
  2637.           $$ = $3;
  2638.           poplevel (0, 0, 0);
  2639.         }
  2640.     ;
  2641.  
  2642. unaryselector:
  2643.       selector
  2644.     ;
  2645.  
  2646. keywordselector:
  2647.       keyworddecl
  2648.  
  2649.     | keywordselector keyworddecl
  2650.         {
  2651.           $$ = chainon ($1, $2);
  2652.         }
  2653.     ;
  2654.  
  2655. selector:
  2656.       IDENTIFIER
  2657.         | TYPENAME
  2658.       | OBJECTNAME
  2659.     | reservedwords
  2660.     ;
  2661.  
  2662. reservedwords:
  2663.       ENUM { $$ = get_identifier (token_buffer); }
  2664.     | STRUCT { $$ = get_identifier (token_buffer); }
  2665.     | UNION { $$ = get_identifier (token_buffer); }
  2666.     | IF { $$ = get_identifier (token_buffer); }
  2667.     | ELSE { $$ = get_identifier (token_buffer); }
  2668.     | WHILE { $$ = get_identifier (token_buffer); }
  2669.     | DO { $$ = get_identifier (token_buffer); }
  2670.     | FOR { $$ = get_identifier (token_buffer); }
  2671.     | SWITCH { $$ = get_identifier (token_buffer); }
  2672.     | CASE { $$ = get_identifier (token_buffer); }
  2673.     | DEFAULT { $$ = get_identifier (token_buffer); }
  2674.     | BREAK { $$ = get_identifier (token_buffer); }
  2675.     | CONTINUE { $$ = get_identifier (token_buffer); }
  2676.     | RETURN  { $$ = get_identifier (token_buffer); }
  2677.     | GOTO { $$ = get_identifier (token_buffer); }
  2678.     | ASM_KEYWORD { $$ = get_identifier (token_buffer); }
  2679.         | SIZEOF { $$ = get_identifier (token_buffer); }
  2680.     | TYPEOF { $$ = get_identifier (token_buffer); }
  2681.     | ALIGNOF { $$ = get_identifier (token_buffer); }
  2682.     | TYPESPEC | TYPE_QUAL
  2683.     ;
  2684.  
  2685. keyworddecl:
  2686.       selector ':' '(' typename ')' identifier
  2687.         {
  2688.           $$ = build_keyword_decl ($1, $4, $6);
  2689.         }
  2690.  
  2691.     | selector ':' identifier
  2692.         {
  2693.           $$ = build_keyword_decl ($1, NULL_TREE, $3);
  2694.         }
  2695.  
  2696.     | ':' '(' typename ')' identifier
  2697.         {
  2698.           $$ = build_keyword_decl (NULL_TREE, $3, $5);
  2699.         }
  2700.  
  2701.     | ':' identifier
  2702.         {
  2703.           $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
  2704.         }
  2705.     ;
  2706.  
  2707. messageargs:
  2708.       selector
  2709.         | keywordarglist
  2710.     ;
  2711.  
  2712. keywordarglist:
  2713.       keywordarg
  2714.     | keywordarglist keywordarg
  2715.         {
  2716.           $$ = chainon ($1, $2);
  2717.         }
  2718.     ;
  2719.  
  2720.  
  2721. keywordexpr:
  2722.       nonnull_exprlist
  2723.         {
  2724.           if (TREE_CHAIN ($1) == NULL_TREE)
  2725.             /* just return the expr., remove a level of indirection */
  2726.             $$ = TREE_VALUE ($1);
  2727.                   else
  2728.             /* we have a comma expr., we will collapse later */
  2729.             $$ = $1;
  2730.         }
  2731.     ;
  2732.  
  2733. keywordarg:
  2734.       selector ':' keywordexpr
  2735.         {
  2736.           $$ = build_tree_list ($1, $3);
  2737.         }
  2738.     | ':' keywordexpr
  2739.         {
  2740.           $$ = build_tree_list (NULL_TREE, $2);
  2741.         }
  2742.     ;
  2743.  
  2744. receiver:
  2745.       expr
  2746.     | CLASSNAME
  2747.         {
  2748.           $$ = get_class_reference ($1);
  2749.         }
  2750.     ;
  2751.  
  2752. objcmessageexpr:
  2753.       '['
  2754.         { objc_receiver_context = 1; }
  2755.       receiver
  2756.         { objc_receiver_context = 0; }
  2757.       messageargs ']'
  2758.         {
  2759.           $$ = build_tree_list ($3, $5);
  2760.         }
  2761.     ;
  2762.  
  2763. selectorarg:
  2764.       selector
  2765.         | keywordnamelist
  2766.     ;
  2767.  
  2768. keywordnamelist:
  2769.       keywordname
  2770.     | keywordnamelist keywordname
  2771.         {
  2772.           $$ = chainon ($1, $2);
  2773.         }
  2774.     ;
  2775.  
  2776. keywordname:
  2777.       selector ':'
  2778.         {
  2779.           $$ = build_tree_list ($1, NULL_TREE);
  2780.         }
  2781.     | ':'
  2782.         {
  2783.           $$ = build_tree_list (NULL_TREE, NULL_TREE);
  2784.         }
  2785.     ;
  2786.  
  2787. objcselectorexpr:
  2788.       SELECTOR '(' selectorarg ')'
  2789.         {
  2790.           $$ = $3;
  2791.         }
  2792.     ;
  2793.  
  2794. objcprotocolexpr:
  2795.       PROTOCOL '(' identifier ')'
  2796.         {
  2797.           $$ = $3;
  2798.         }
  2799.     ;
  2800.  
  2801. /* extension to support C-structures in the archiver */
  2802.  
  2803. objcencodeexpr:
  2804.       ENCODE '(' typename ')'
  2805.         {
  2806.           $$ = groktypename ($3);
  2807.         }
  2808.     ;
  2809.  
  2810. %%
  2811.